This is the source code to observe the virtual function table:
#include <iostream>
using namespace std;
class Base
{
public:
virtual void func() {}
virtual ~Base() {}
protected:
int x;
};
class Derived : public Base
{
public:
virtual ~Derived() {}
virtual void func2() { cout << " func2() " << endl; }
protected:
int y;
};
int main()
{
Base b;
Derived d;
cout << endl;
return 0;
}
I use the vs2012 and debug to the "cout << endl;" statement, then I find that the member function "func2" does not appear in the virtual function table, there are only Base::func() and Derived::~Derived().
d
->Base
->__vfptr
, butBase
's vtable has no need/place forfunc2
. Check if you can findDerived
's vtable. – Daniel FreyBase
(as the OP did in the debugger), you only see the first part which contains all the thingsBase
knows about. You need to look at it throughDerived
to see the additional slots forfunc2
, etc. This probably means that the debugger is simply too stupid to show all the information as the vtable-ptr is stored in theBase
-part of theDerived
instance and when the debugger tries to show it, it looses the information thatd
isDerived
and could therefore useDerived
's vtable. – Daniel Frey