M
Marco
Hi all,
I have a base class and some subclasses; I need to define an array of
objects from these various subclasses. What I have is something like:
{
//I have a base class, something like:
class CPeople {
public:
virtual void Input() {printf("Inside CPeople::Input()\n");}
virtual void Show() {printf("Inside CPeople::Show()\n");}
};
//and some subclasses
class CMale : public CPeople {
public:
void Input() {};
void Show() {};
};
class CFemale : public CPeople {
public:
void Input() {printf("Inside CFemale::Input()\n");}
void Show() {printf("Inside CFemale::Show()\n");}
};
//Now I need an array of people...
CPeople MyArray[10];
//I create a CFemale Object...
CFemale temp;
temp.Input();
//I assign this object to an array element:
MyArray[1] = temp;
MyArray[1].Show();
return 0;
}
// I get :
// "Inside CFemale::Input()"
// "Inside CPeople::Show()"
So when I call MyArray[1].Show() the function called is the one
defined in the base class ( CPeople::Show() ).
What do I need to do to get the desired behaviour?
Thank you in advance...
Marco
I have a base class and some subclasses; I need to define an array of
objects from these various subclasses. What I have is something like:
{
//I have a base class, something like:
class CPeople {
public:
virtual void Input() {printf("Inside CPeople::Input()\n");}
virtual void Show() {printf("Inside CPeople::Show()\n");}
};
//and some subclasses
class CMale : public CPeople {
public:
void Input() {};
void Show() {};
};
class CFemale : public CPeople {
public:
void Input() {printf("Inside CFemale::Input()\n");}
void Show() {printf("Inside CFemale::Show()\n");}
};
//Now I need an array of people...
CPeople MyArray[10];
//I create a CFemale Object...
CFemale temp;
temp.Input();
//I assign this object to an array element:
MyArray[1] = temp;
MyArray[1].Show();
return 0;
}
// I get :
// "Inside CFemale::Input()"
// "Inside CPeople::Show()"
So when I call MyArray[1].Show() the function called is the one
defined in the base class ( CPeople::Show() ).
What do I need to do to get the desired behaviour?
Thank you in advance...
Marco