As far i know when we make a function virtual in base class a pointer which can be referred as vptr is created by the compiler and a vtable which holds the entrys of virtual function which are latest version for this class in case of overridden function .and the vptr points to the vtable. classes that are derived from the base class have the same story , they have a pointer vptr and own vtable which holds the entrys of the latest virtual function . To understand my question follow the code
#include <iostream>
using namespace std;
class base
{
public:
virtual void display(void)
{
cout << "base\n";
}
};
class derived : public base
{
public:
void display(void)
{
cout << "derived\n";
}
};
int main(void)
{
base *p;
base ob1;
derived ob2;
p=&ob2;
p->display();//my point starts from here
p->base::display();
}
In the above code the statement p->display(); it does make sense that the object p points call the vptr of this class and look up for display function from the vtable and bind it. But i am not understanding that how would i describe the statement p->base::display(); in terms of vptr and vtable .how the compiler will bind the display function of base class version .As there would be no display function of base class version in the vtable of the derived class. If anything my knowing would wrong here , please tell me what the right is . And if i am right then tell me how will i describe the p->base::display(); statement with the logic i described p->display(); statement