DIR Return Create A Forum - Home
---------------------------------------------------------
ifaq
HTML https://ifaq.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: C/C++ related questions
*****************************************************
#Post#: 6--------------------------------------------------
C++ class sizes
By: avinash.srin Date: August 25, 2011, 9:41 am
---------------------------------------------------------
What is the size of an empty class? What is the size of a class
with one virtual function? Explain the reasons behind.
#Post#: 19--------------------------------------------------
Re: C++ class sizes
By: avinash.srin Date: August 26, 2011, 6:37 am
---------------------------------------------------------
The size of an empty class in C++ is one byte. This is to make
sure that two objects don't have the same address.
The size of a class with one virtual function is four bytes (One
word). The same for many virtual functions also. This is because
objects of a class with a virtual function requires space needed
by the virtual function call mechanism (vptr) - typically one
word per object.
*****************************************************