You may be able to use typeid for this.
#include <cstdio>
#include <typeinfo>
class Base {
virtual int foo() { return 0; }
};
class A : public Base {
};
class B : public Base {
};
void some_func(Base *p) {
printf("the name of class: %s\n", typeid(*p).name() );
}
int main() {
some_func(new A);
}
Unfortunately it will probably not do what you want unless your base class has at least one virtual function (otherwise the type information may not be available).
Unlike __PRETTY_FUNCTION__
, the value you are looking for cannot be computed at compile time.