class Base
{
public:
virtual void func1()
{
std::cout<<"Base func1"<<std::endl;
}
//virtual destructor
};
class Derived : public Base
{
public:
virtual void func1()
{
std::cout<<"Derived Base func1"<<std::endl;
}
virtual void func2()
{
std::cout<<"Derived func2"<<std::endl;
}
};
int main()
{
Derived *d = new Derived;
delete d;
}
I want to know if there will be two "vptr"s created for resolving virtual functions, one in the Base class which will be inherited in Derived class object for func1 and other one in the Derived object for func2.
On my GCC:
So one vtable pointer is enough. I'd expect most other compilers to behave in the same way.
Virtual functions added in
Derivedare probably simply placed at the end ofDerivedvtable, after functions inherited fromBase.