Afficher un message
Vieux 29/06/2008, 19h52   #1
Peskov Dmitry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Memory layout of class

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.
  Réponse avec citation
 
Page generated in 0,05833 seconds with 9 queries