On 5/8/07, Gopi Krishna Komanduri <[EMAIL PROTECTED]> wrote:
> Hi,
>       I know that size of empty class is 1 byte. But when we write a class 
> compiler will provide , default constructor , default destructor , copy 
> constructor (shallow)  , and one assignment operator overloading functions 
> whether the class is empty or not. So , in copy constructor , and in 
> assigment operator methods , the implementation wil use "this" pointer. So 
> the empty class should have one hidden this pointer. and when we create 
> object , the this pointer will start pointing to the current object. So the 
> size of empty class shuld be atleast size of a pinter (2 bytes , but depends 
> on compiler). Could you please clarify!

A pointer might be 2 bytes on your compiler (something tells me it's
Turbo C++), but on modern systems it is 4 or 8 bytes.
However, the size of the pointer is irrelevant in this case: the class
does not have a pointer to itself, because you supply the this pointer
implicitly when you call a member of an object.
The size of the empty class is one bytes because the pointer needs to
point somewhere, and if it would be 0 then one pointer could point to
multiple instances which is not good.
I hope it's more clear now.

-- 
Tamas Marki

Reply via email to