Afficher un message
Vieux 29/06/2008, 20h31   #3
Tarique
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Memory layout of class

Peskov Dmitry wrote:
> Hi,
> What is the memory layout of an object, and the derived object.
> For example :
>
> class A
> {
> private:
> int prv_data;
> protected:
> int pro_data;
> public:
> int pub_data;
> A(){prv_data = 10;}
> void Aprint();
> };
>
> class B : public A
> {
> int pro_data;
> public:
> void Bmember1();
> void Bprint();
> };
>
> Does it depend on the compiler ?
>
> int main()
> {
> B b;
> int *ptr;
>
> ptr = (int *)&b;
> *ptr = 1000;
> ptr++;
> *ptr = 2000;
> ptr++;
> *ptr = 3000;
> ptr++;
> *ptr = 4000;
>
> return 0;
> }
>
> is setting only the private element of class A to 1000, rest are not
> being set.


See
http://www.research.att.com/~bs/bs_faq2.html#layout-obj

  Réponse avec citation
 
Page generated in 0,04499 seconds with 9 queries