Once upon a time there was something called taligent, some code ended up in the java world, some ended up as part of IBM's C++ class library. I havent looked at that library for many years, but if I remember correcty there was something there that might have done something akin to what I think you want. This was in the days before static_, dynamic_, cast became a part of the c++ language, but the functionality of dynamic_cast was needed.
If I remember correctly each class definition contained a macro that added an entry to a global map for each class and it's parent class. This defined the inheritance tree for the entire library in an extensible manner.
As I said - if I remember correctly ...
The functionality was used to simulute dynamic_cast, as in validate that it was "right" to cast from one type to another, and to retrieve the name of the type for a given object.
This method only supported single inheritance, and a cast was considered valid if it was from a base class to a descandant class. The object had to be of, or descend from, the target type of the cast.
Not that I would advice you to do anything like that today.
C++ Primer[
^], by Stanley B. Lippman makes for an excellent reading.
Update:
Java supports reflection
Take look at this article:
Metaclasses and Reflection in C++[
^]
The map mentioned earlier was a very simplistic metadata container ...
Regards
Espen Harlinn