Re: call base class function or derived class function
Abhishek Padmanabh wrote:
"George" <George@discussions.microsoft.com> wrote in message
news:74F39427-6E0E-46CA-9D92-EF3C79D99651@microsoft.com...
Thanks Igor,
You could a) look at vtable under debugger, or b) try to call the
I doubt whether method (a) works. You know we can not create an
object of abstract class, and we can only create an instance of
derived class. How could we monitor the vtable of the abstract base
class to see whether the pure virtual method of base class is in
vtable of instance of abstract base
class?
And if we can create an instance of derived class, it means it
implements the pure virtual method, then in the vtable of instance
of derived class, it
should be the virtual method of derived class, not the pure virtual
method of
abstract base class.
a) should work. You cannot create an object of abstract class type
but that is not a problem. I might be misreading the debugger but I
think that the abstract class' v-table is not needed and hence not
The compiler cannot avoid generating the abstract class v-table in all
cases. Consider:
During the execution of the abstract base class constructor, the dynamic
type is the abstract class. The exact type is statically known, so when the
constructor calls any member function the call is non-virtual. However, the
constructor may call a member function which in turn calls a virtual
function. This helper function cannot guarantee the dynamic type, because
it could be called outside the constructor as well. Hence it must call
through the v-table. But the dynamic type of the object is the abstract
type, the derived class v-table cannot be used. Hence vfptr must point to
the abstract class v-table.