如何在C ++中的typeof [英] How to typeof in C++
本文介绍了如何在C ++中的typeof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C ++中模拟C#typeof-command行为?
How to simulate C# typeof-command behavior in C++?
C#example:
C# example:
public static PluginNodeList GetPlugins (Type type)
{
...
}
调用:
PluginManager.GetPlugins (typeof(IPlugin))
如何使用C ++实现?也许QT或Boost库提供了一个解决方案?
How to implement this using C++? Maybe QT or Boost libraries provide a solution?
如果你想实现.GetPlugins(...)的方式,它加载这些种类的对象从文件(.so或.dll)?
What about the case if you want to implement .GetPlugins(...) in a way that it loads those kinds of objects from a file (.so or .dll)?
推荐答案
您可以使用dynamic_cast测试类型,如下所示: p>
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
}
这篇关于如何在C ++中的typeof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文