Afficher un message
Vieux 30/06/2008, 06h10   #6
Jerry Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Memory layout of class

In article <2f35231f-96fc-406a-a078-d77fbb1799d6
@i18g2000prn.googlegroups.com>, vamsi.komati@gmail.com says...
> Hi,
> What is the memory layout of an object, and the derived object.


[ ... ]

> Does it depend on the compiler ?


Partly. If there's no private/public/protected label between them, items
in an object are required to be placed at increasing addresses. When
there is an intervening private/protected/public label, there is no
guarantee about relative ordering from the standard.

As far as base classes go, IF you're dealing with single inheritance
quite a few compilers put the base class at the beginning of the derived
class. This makes it trivial to convert an object to its base class
object (i.e. the same address, treated as a pointer to the base class,
works). Obviously when you have multiple inheritance, the compiler can
only place one base class at the beginning of the derived class objects.

--
Later,
Jerry.

The universe is a figment of its own imagination.
  Réponse avec citation
 
Page generated in 0,04613 seconds with 9 queries