- 30
- 0
- 约 56页
- 2016-11-14 发布于湖北
- 举报
5.5 派生类的构造函数和析构函数 #include iostream.h #include string.h class person {public: person (int i, string nam) { id = i; name = nam; } void display( ) { cout“id:”idendl; cout“name:”nameendl; } protected: int id; string name; }; class student : public person { public: student( int i, string nam, int pid, string pnam, int sid) : person( i, nam),parent(pid,pnam) { stuid = sid; } 派生类构造函数任务:1,初始化基类数据成员;2,初始化子对象数据成员;3,初始化派生类新增数据成员。 void show( ) {cout“id:”idendl; cout“name:”nameendl; cout“stuid:”stuidendl; } void sho
原创力文档

文档评论(0)