C++“爸爸”类和“妈妈”类共同采用虚基类的方式继承了“人”类(包含成员年龄)
答案:1 悬赏:50 手机版
解决时间 2021-03-17 05:03
- 提问者网友:愿为果
- 2021-03-16 17:10
C++“爸爸”类和“妈妈”类共同采用虚基类的方式继承了“人”类(包含成员年龄)
最佳答案
- 五星知识达人网友:舊物识亽
- 2021-03-16 18:20
class pp
{
int age;
public:
pp(int a=0):age(a){}
virtual void prt() = 0;
};
class bb : virtual public pp
{
int age;
public:
bb(int a = 0) :pp(a) {}
void prt()
{
cout << age << endl;
}
};
class mm : virtual public pp
{
int age;
public:
mm(int a = 0) :pp(a) {}
void prt()
{
cout << age << endl;
}
};
class cd : public bb, public mm
{
int age;
public:
cd(int a=0): age(a){}
void prt()
{
cout << age << endl;
}
};
int main()
{
cd c(10);
c.prt();
getch();
return 0;
}
{
int age;
public:
pp(int a=0):age(a){}
virtual void prt() = 0;
};
class bb : virtual public pp
{
int age;
public:
bb(int a = 0) :pp(a) {}
void prt()
{
cout << age << endl;
}
};
class mm : virtual public pp
{
int age;
public:
mm(int a = 0) :pp(a) {}
void prt()
{
cout << age << endl;
}
};
class cd : public bb, public mm
{
int age;
public:
cd(int a=0): age(a){}
void prt()
{
cout << age << endl;
}
};
int main()
{
cd c(10);
c.prt();
getch();
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯