Why Virtual base class increase the size of class by 4 bytes?
Hi all,
Well I have a quick doubt on virtual base class:
can sombody explain?
I am going to write 2 c++ program please check output.
Code:
#include<iostream>
using namespace std;
class base
{
int i;
};
class derived: public base
{
};
void main()
{
cout<<"size of class derived is "<<sizeof(derived)<<endl;
}
OUTPUT:
size of class derived is 4
Press any key to continue
With virtual:
#include<iostream>
using namespace std;
class base
{
int i;
};
class derived:virtual public base
{
};
void main()
{
cout<<"size of class derived is "<<sizeof(derived)<<endl;
}
OUTPUT:
size of class derived is 8
Press any key to continue