hi all,
i'm new to C++ and i'm stuck at a very strange looking issue related to virtual functions of derived class.
I have code as below. During execution when putting breakpoint in last statement of main() function, i can see a vptr in (ptr to vtable) in base class obj b1 and same type of vptr in base class under object of derived class (d1) but i'm not able to see another exclusive vptr for derived obj d1 for func1(). Why??
insert
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
class base{
public:
int nSize;
virtual void get();
virtual void set();
};
void base::get()
{
cout << endl << "get() of base";
}
void base::set()
{
cout << endl << "set() of base";
}
class der: public base
{
public:
char ch;
void get(); // override virtual base get()
virtual void func1();
};
void der::get()
{
cout << endl << "get of der1";
}
void der::func()
{
cout<< endl << "func of der";
}
int main()
{
base b1;
der1 d1;
b1.get(); // vptr suggest base::get() and base::set()
d1.get(); // vptr is present under base part of d1 and suggest der1::get()
d1.func(); // no vptr under d1, but still code executes.
return 0;
}