How to retrieve C++ class info other then RTTI

481 Views Asked by At

Here are three classes,

class ClassA{};
class ClassB:public ClassA{};
class ClassC:public ClassB{};

ClassC cobject;

I want to know the cobject's "Class Name"(i.e. ClassC) and its "SuperClasses' Name"(i.e. ClassB & ClassA)

I know RTTI can do this. But I'm wondering if I can do this with a few macros.

1

There are 1 best solutions below

0
On

The short answer is no, you can't do that with a few macros if you don't want to use RTTI.

However, you can get a lot of useful information about class types using templates on your own or using a library like the Boost.TypeTraits. For example, you can test if a class inherits from another using is_base_of()