How to typeof in C++

前端 未结 8 1554
再見小時候
再見小時候 2020-12-10 18:30

How to simulate C# typeof-command behavior in C++?

C# example:

public static PluginNodeList GetPlugins (Type type)
{
 ...
}

Call:

相关标签:
8条回答
  • 2020-12-10 19:21

    You could use a dynamic_cast to test types as shown below:

    IPlugin* iPluginPtr = NULL;
    iPluginPtr = dynamic_cast<IPlugin*>(somePluginPtr);
    
    if (iPluginPtr) {
        // Cast succeeded
    } else {
        // Cast failed
    }
    
    0 讨论(0)
  • 2020-12-10 19:24

    You can use typeof() in GCC. With other compilers, it's either not supported or you have to do crazy template mangling or use "bug-features" that are very compiler specific (like the way Boost does it).

    0 讨论(0)
提交回复
热议问题