I need help with an assignment for my programming course.
I have three classes A,B,C. all stored in one array.
(These are not my real classes there are just a guide)
Class A{
char name;
public:
virtual print(){ printf("%s",name); }
}
Class B : public A{
char middleName;
public:
print(){ A::print(); printf("%s", middleName); }
}
Class C : public B{
char lastName;
public:
print(){ printf("%s",lastName); }
}
/*I wish to call the print from all the classes, assume this array is full of a variaty of A,B,C */
A* classes[20];
classes[0]->print();
classes[1]->print();
........
This works fine for classes A and B. B will print the common info from A then its own.
But this is not the case for Class C, -> seems to call the B::print() rather than C::print(). so i cannot print the lastName.
The assignment states explicitly that C inherits from B.
(perhaps multiple inheritance is needed?)
any ideas? thanks in advance.
gilly
(for those that don't want to help me "cheat" on my work i can assure you this is a small part of the assignment that i am stuck on)