Is there any way to get the classname, classmembers and classmethods of a object or klass in C++?
In Java I can use:
Object.getClass().getMethods()
Object.getClass().getName()
Object.getClass().getDeclaredMethods();
Object.getClass().getDeclaredFields();
Object.getClass().getMembers();
I know there is the metaObject-Class in QT. But i don't want use this framework. Is there something else in the boost-libary or STL?
http://doc.qt.digia.com/qt/metaobjects.html#meta-object-system
谢谢。
最佳答案
在C++ 11中无法获得一般的反射(reflect)。您最能做的就是通过std::type_info
运算符使用运行时类型信息获取对象的类型作为typeid
。
可以继承此type_info,使您能够手动将一些额外的类型信息烘焙到类型中,并且可以根据需要自定义它。在Bjarne Stroustrup的书“C++编程语言”和“C++的设计与演变”中对此作了更详尽的解释,但是我无法快速找到它的网络引用。
如您的问题所述,要进行全面思考,您将不得不等待并希望该标准的将来版本中可用。 C++标准委员会第7小组(SG7)目前正在为此工作:
http://isocpp.org/std/the-committee
关于c++ - C++ object.getClass()。getMethods(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13799792/