As the title asks, are they any g++ builtin function (or any method) to know the class name from a class object pointer?
For instance,
class Base {
};
class A : public Base {
};
class B : public Base {
};
void some_func(Base *p) {
printf("the name of class: %s", __some_g++_builtin_get_class_name(p) );
}
Similar to __PRETTY_FUNCTION__ in gcc builtin, I hope there would be a builtin function for g++ that help us analyze source code 🙂
You may be able to use typeid for this.
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.