RTTI and Reflection for C++

Posted by Kaya Kupferschmidt • Wednesday, March 15. 2006 • Category: C++
One important and useful feature is missing in C++: Reflection. Reflection is the ability of a language to acquire information about objects at runtime. Of course C++ has a typeid operator, but the use of the returned type_info is very limited and compiler dependant. What one is actually seeking for is complete information not only about class inheritance but also about all members and methods of each class.

Exactly this king of information offers the Reflex library developed at CERN. You can get all kinds of information about every object and class in your system, you can even instanciate new objects at runtime using string-literals describing a class and invoke any method of an object. One special advantage of this package is that it works in an absoultely non-intrusive manner, meaning that you do no have to change a single line of your code in order to get reflection. Instead of changing your code, Reflex relies on the gccxml parser that generates rich XML information about your classes. This information is then automatically transformed into some additional files containing cpp code containing all neccessary dictionaries and bindings to your code to enable full reflection.

Imagine the possibilities of such a system: You can easily integrate a scripting language into your program in a very generic manner if you use the rflection information provided by the Reflex library. WIth some additional work it should also be possible to serialise your objects to disk for providing persistent storage semantics. It even should be possible to implement some remote procedure calls building upon the reflection information provided by Reflex.


Display comments as (Linear | Threaded)
  1. *The links on your blog now does not work .. in both Firefox 1.5 and MSIE 6.0 .. I just can see the window which "should be JavaScript" closed, and no new window with the link target.

  2. *Thank you for your comment. But unfortunately (or luckily?) I cannot reproduce the behaviour you mentioned. Maybe your browser settings are too restrictive? On the other hand no JavaScript should be involved in clicking on links, only some forwarding.

  3. *Its probably some problem with our squid cache (combined with Ad-Zapper) at work. At home, when direct connected, it works without any flaws. Will check later thoroughly where is the problem.

    Anyway, thanks for pointing out the Reflex, I haven't know it exists till now. Unfortunately, my brain already blocked dreaming about reflection, so it may take some time to adapt to the idea.

    One thing I miss in C++ is good implementation of delegates, so one can store callback (e.g. virtual method call) including its parameters and call them later. I found some tricky implementations, but none was ideal for me.

  4. *Reflection is such a nice thing. Currently we implement a service oriented framework with an XML based configuration using Reflex. This enables us to specify methods within the XML file that should be called when a module is loaded.

    Delegates are really another subject, I know what you mean. I am also searching for some nice solution, but it seems to be hard. Maybe (hopefully!) the next C++ standard will include them.

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Markdown format allowed

A Simple Sidebar