小编Raw*_*awr的帖子

C++函数指针与Switch

  • 什么是更快:功能指针或开关?

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. …

c++ performance

18
推荐指数
2
解决办法
9925
查看次数

MSVC 在哪些方面不符合标准?

我读到 MSVC 不完全符合 ISO C++ 标准(德语维基百科和几个技术网站)。

  • C++ 标准在哪些方面不兼容?

c++ visual-c++

5
推荐指数
1
解决办法
805
查看次数

标签 统计

c++ ×2

performance ×1

visual-c++ ×1