#include <iostream>
using std::cout;
using std::endl;
class ObjectA {
public:
ObjectA(int x):value_(x) {}
virtual void funcA()
{cout << "ObjectA funcA" << endl;}
virtual void funcA1()
{cout << "ObjectA funcA1" << endl;}
private:
int value_;
};
void printVirtualTable(ObjectA* objA)
{
typedef void (*funcPtr)();
funcPtr* vptr = (funcPtr*)(*((uint64_t*)objA));
while (*vptr) {
fprintf(stdout, "%p ", *vptr);
vptr++;
}
}
int main()
{
ObjectA* objA = new ObjectA(19);
printVirtualTable(objA);
return 0;
}
ObjectA
has 2 virtual methods, so I think the size of the vtable is 2, but printVirtualTable
shows there are 3 pointers in the vtable, the first and second pointers are funcA
and funcA1
, but what is the third one?