This obviously depends on the implementation, but in most implementations, the representation of an object of class A or B in memory starts with a pointer to vtable. You can look at this vtable pointer, compare it with vtable pointers for objects that, as you know, have class A or B , and define the class of the object this way.
To illustrate (of course, this is nothing but a good style):
A *pFoo=new B();
Important: this is just an illustration of how most implementations work; in addition to being implementation dependent, this method breaks down when there is multiple inheritance. You should not do anything like this in production code; use RTTI instead.
Martin B
source share