How to typeof in C++

前端 未结 8 1559
再見小時候
再見小時候 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(somePluginPtr);
    
    if (iPluginPtr) {
        // Cast succeeded
    } else {
        // Cast failed
    }
    

提交回复
热议问题