1.000s128MB派生类Student的构造函数和析构函数
已知基类Person的定义如下:
class Person
{ char Name[10]; //姓名
int Age; //年龄
public:
Person(char* name,int age)
{ strcpy(Name, name);
Age = age;
cout<<"constructor of person "<<Name<<endl; }
~Person()
{ cout<<"deconstructor of person "<<Name<<endl; };
请通过继承的方法建立一个派生类Student,其中
1.新增的数据成员有:
char ClassName[10]; //班级
Person Monitor; //班长
2.新增的成员函数有:
Student(char *name, int age, char *classname, char *name1, int age1) //name1和age1是班长的信息
~Student()
在主程序中建立一个派生类对象。
张弓长 18 计算机51 李木子 20
constructor of person 张弓长
constructor of person 李木子
constructor of Student
deconstructor of Student
deconstructor of person 李木子
deconstructor of person 张弓长
注意:person为小写,单词间有一个空格。