switch语句大约需要30 case秒,包括从0到30的被禁止的无符号整数.
我可以做以下事情:
class myType
{
FunctionEnum func;
string argv[123];
int someOtherValue;
};
// In another file:
myType current;
// Iterate through a vector containing lots of myTypes
// ... for ( i=0; i < myVecSize; i ++ )
switch ( current.func )
{
case 1:
//...
break;
// ........
case 30:
// blah
break;
}
Run Code Online (Sandbox Code Playgroud)
func每次都要通过开关.关于切换的好处还在于我的代码比30个函数更有条理.
或者我可以这样做(不太确定):
class myType
{
myReturnType (*func)(int all, int of, int my, int args );
string argv[123];
int someOtherValue;
};
Run Code Online (Sandbox Code Playgroud)
我有30个不同的函数,在开始时,指向其中一个的指针被分配给myType. …
我读到 MSVC 不完全符合 ISO C++ 标准(德语维基百科和几个技术网站)。