M
MUTOOLS
class A {
public:
char String[20];
};
class B : public A {
public:
char String[20];
};
class C : public B {
public:
char String[20];
};
void Test() {
A a,*ap;
B b;
C c;
strcpy(a.String,"Adios");
strcpy(b.String,"ByeBye");
strcpy(c.String,"Ciao");
printf("%s\n",a.String); // prints 'Adios' -> OK
printf("%s\n",b.String); // prints 'ByeBye' -> OK
printf("%s\n",c.String); // prints 'Ciao' -> OK
ap=&a;
printf("%s\n",ap->String); // prints 'Adios' -> OK
ap=&b;
printf("%s\n",ap->String); // prints 'IIIIIIIIIIIIIIIIIIIIByeBye' -> Strange! Why?
ap=&c;
printf("%s\n",ap->String); // prints 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIICiao' -> Strange! Why?
}
When doing
ap=&b;
Why doesn't ap->String show "Adios"? Or "ByeBye"? (that was what i wanted to test)
I searched the net but couldn't find the answer. Lot of info about deriving member functions, but not about deriving member variables.
Any answer or links are much appreciated.
Thanks.
public:
char String[20];
};
class B : public A {
public:
char String[20];
};
class C : public B {
public:
char String[20];
};
void Test() {
A a,*ap;
B b;
C c;
strcpy(a.String,"Adios");
strcpy(b.String,"ByeBye");
strcpy(c.String,"Ciao");
printf("%s\n",a.String); // prints 'Adios' -> OK
printf("%s\n",b.String); // prints 'ByeBye' -> OK
printf("%s\n",c.String); // prints 'Ciao' -> OK
ap=&a;
printf("%s\n",ap->String); // prints 'Adios' -> OK
ap=&b;
printf("%s\n",ap->String); // prints 'IIIIIIIIIIIIIIIIIIIIByeBye' -> Strange! Why?
ap=&c;
printf("%s\n",ap->String); // prints 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIICiao' -> Strange! Why?
}
When doing
ap=&b;
Why doesn't ap->String show "Adios"? Or "ByeBye"? (that was what i wanted to test)
I searched the net but couldn't find the answer. Lot of info about deriving member functions, but not about deriving member variables.
Any answer or links are much appreciated.
Thanks.