《C++面向对象程序设计》谭浩强第五章.pptVIP

  • 30
  • 0
  • 约 56页
  • 2016-11-14 发布于湖北
  • 举报

《C++面向对象程序设计》谭浩强第五章.ppt

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)

1亿VIP精品文档

相关文档