当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 派生类Student的构造函数和析构函数 代码参考

派生类Student的构造函数和析构函数 代码参考

2020年04月22日  | 移动技术网IT编程  | 我要评论

折叠篮,035400,王军霞现任丈夫李辉阳

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 using namespace std;
 5 
 6 class person
 7 {
 8     private:
 9         char name[10];
10         int age;
11     public:
12         person(char *name, int age)
13         {
14             strcpy(name,name);
15             age=age;
16             cout<<"constructor of person "<<name<<endl;
17         }
18         ~person(){cout<<"deconstructor of person "<<name<<endl;}
19 };
20 
21 class student:public person
22 {
23     private:
24         char classname[10];
25         person monitor;
26     public:
27         student(char *name, int age, char *classname, char *name1, int age1);
28         ~student();
29 };
30 
31 student::student(char *name, int age, char *classname, char *name1, int age1):person(name,age),monitor(name1,age1)
32 {
33     strcpy(classname,classname);
34     cout<<"constructor of student"<<endl;
35 }
36 
37 student::~student()
38 {
39     cout<<"deconstructor of student"<<endl;
40 }
41 
42 int main()
43 {
44     char name1[10],name2[10],classname[20];
45     int age1,age2;
46     cin>>name1>>age1>>classname>>name2>>age2;
47     student one(name1,age1,classname,name2,age2);
48     return 0;
49 }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网