Afficher un message
Vieux 30/06/2008, 05h10   #5
EventHelix.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Memory layout of class

On Jun 29, 1:52pm, Peskov Dmitry <vamsi.kom...@gmail.com> 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.


The memory layout of a class is compiler dependent. The following
article should :

http://www.eventhelix.com/realtimema...erformance.htm

Memory layout for inherited classes is explained in:

http://www.eventhelix.com/realtimema...formance2..htm

--
http://www.EventHelix.com/EventStudio
Sequence diagram based systems engineering tool
  Réponse avec citation
 
Page generated in 0,05946 seconds with 9 queries