Gopi Krishna Komanduri wrote:
> Hi Tamas Marki,
>           I agreed for your explanation. But , consider a code for 
> copy constructor or assignment operator overloading methods. Those 
> will be provided irrespective of whether we create objects or not. Am 
> I correct? If so , in side the code , the implementation wil be with 
> "this"   pointer itself na! .. Even if we think like the assignment 
> for this pointer will be  done by creation of object(passing &obj as 
> hidden parameter and catching this address into this pointer  and 
> using it , ) even in this xcase also .. some memory will be occupied 
> for formal parameters and that included the size of this pointer also na!
>      Please correct me where I missed the track!   
the object doesn't have a "hidden this pointer"  calls to methods are 
provided "this" as an argument
>    Thanks&Regards,
>  Gopi.k
>
> Tamas Marki <[EMAIL PROTECTED]> wrote:
>          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.
>

Reply via email to