1

Possible Duplicate:
How can I add reflection to a C++ application?

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

Thanks.

Community
  • 1
  • 1

2 Answers2

3

There is no way to get general reflection in C++11. The closest you can do is getting an object's type as a std::type_info using Run-Time Type Information via the typeid operator.

This type_info can be inherited from, giving you the ability to manually bake in some extra type information into your types, and you can customize it as you want. This is explained more thoroughly in Bjarne Stroustrup's books "The C++ Programming Language" and "The Design and Evolution of C++", but I can't quickly find a web reference for it.

For full reflection, as mentioned in your question, you will have to wait and hope that this will be available in future versions of the standard. The C++ Standard Committee Subgroup 7 (SG7) are currently working on this:

http://isocpp.org/std/the-committee

Agentlien
  • 4,996
  • 1
  • 16
  • 27
0

Nowadays C++ (even C++11) has no such feature (reflection), but this feature will be discussed for C++14: See also here and here (group SG7)

zaufi
  • 6,811
  • 26
  • 34