#include <iostream> using namespace std; void main(){ class timetype{ int second,minute,hour; public: timetype(int s=0,int m=0,int h=0){second=s;minute=m;hour=h;} void timeset(int s,int m,int h){second=s;minute=m;hour=h;} void display(){ cout<<"The current time is: "<<hour<<':'<<minute<<':'<<second<<endl;} }; class datetype{ int day,month,year; public: datetype(int d=1,int mo=1,int y=2000){day=d;month=mo;year=y;} void dateset(int d,int mo,int y){day=d;month=mo;year=y;} void display(){ cout<<"The current date is: "<<day<<'/'<<month<<'/'<<year<<endl;} }; class datetimetype:public datetype,public timetype{//多重派生 public: datetimetype(int s=0,int m=0,int h=0,int d=1,int mo=1,int y=2000):timetype(s,m,h),datetype(d,mo,y){};//派生类新增加成员的初始化; void display(){ datetype::display(); timetype::display(); } }; datetimetype t1; cout<<"The initial time is: "<<endl; t1.display(); t1.timeset(56,20,0);//由于timeset 在基类timetype中为public,而且派生datetimetype时也是public派生故可直接访问基类成员函数 member function t1.dateset(21,7,1988); cout<<"The modified time is: "<<endl; t1.display(); }
原文链接: https://www.cnblogs.com/leeking/archive/2012/09/11/2680079.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/62474
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!