Class CSchoolPerson
{
public:
CSchoolPenson(){};
virtual CSchoolPenson(){};
public:
virtual void WhoAmI()
{
printf("i am a schoolperson/n");
}
}
Class CTeacher : public CSchoolPerson
{
public:
CTeacher(){};
virtual CTeacher(){};
public:
virtual void WhoAmI()
{
printf("i am a Teacher/n");
}
}
Class CStudent : public CSchoolPerson
{
public:
CStudent(){};
virtual CStudent(){};
public:
virtual void WhoAmI()
{
printf("i am a Student/n");
}
}
void main()
{
CSchoolTeacher *pteacher = new CTeacher;
CStudent *pstudent = new CStudent;
CArray<CPerson,CPerson*> ob;
ob.add(pteacher);
ob.add(pstudent);
for(int i = 0;
i < ob.GetSize();
i ++)
{
CPerson *pPerson = ob.GetAt(i);
pPerson->WhoAmI();
}
}
大致上是这个样子,我没有用编译器来确定是否通过运行,
只是随便打出来的。