Possible Duplicate:
Empty class in C++
class Class1
{
char c;
};
class Class2
{
};
What is the size of Class1 and Class2?
In VC6, I got both 1. can someone explain this?
Possible Duplicate:
Empty class in C++
class Class1
{
char c;
};
class Class2
{
};
What is the size of Class1 and Class2?
In VC6, I got both 1. can someone explain this?
No class can ever have size less than one, because pointer arithmetic (specifically the subtraction operator) can divide by the size, and division by zero is undefined. It's also necessary that every instance have a unique address, which means that at least one byte of address space has to be given to each, hence minimum size is again one.
So sizeof (Class1) == 1
because that's what is needed for the content, and sizeof (Class2) == 1
because that's the minimum allowed.