Just omit decltype :
void print() { std::cerr << typeid(*this).name(); };
this always points to an instance of a class whose member function is inside. this inside A always A* . So typeid(decltype(*this)) always gives you A
On the other hand, typeid(*this) will look for runtime information that will determine if this really B (because A is a polymorphic type).
Barry
source share