Hi,
I did know that the size of a class is increased by 4 bytes (32bit compiler) if the class has a virtual function.
I wrote one program and it is giving strange output.
I am using linux g++ compiler.
The program and output is as below
output=4Code:#include<iostream> using namespace std; class Base { public: void fun() { } private: int i; }; int main() { cout<<sizeof(Base)<<endl; return 0; }
output is 16Code:#include<iostream> using namespace std; class Base { public: virtual void fun() { } private: int i; }; int main() { cout<<sizeof(Base)<<endl; return 0; }
please clarify


Reply With Quote
Bookmarks