- #include
- //多继承
- using namespace std;
- //封装沙发 类
- class Sofa
- {
- private:
- string sitting;
- public:
- Sofa(){cout<< "父类sofa无参构造函数" << endl;}
- Sofa(string s):sitting(s)
- {
- cout << "父类sofa有参构造函数" << endl;
- }
- //拷贝构造函数
- Sofa(const Sofa &other):sitting(other.sitting)
- {
- cout << "父类Sofa拷贝构造函数" << endl;
- }
- //拷贝赋值函数
- Sofa &operator=(const Sofa &other)
- {
- cout << "父类Sofa拷贝赋值函数" << endl;
- sitting=other.sitting;
- return *this;
- }
- ~Sofa()
- {
- cout << "父类sofa析构函数" << endl;
- }
- void show()
- {
- cout << sitting<< endl ;
- }
-
- };
-
-
- //封装 桌子 类
- class Table
- {
- private:
- string material;
- int quaty;
- public:
- Table(){cout << "父类Table无参构造函数" << endl;}
- Table(string material,int quaty):material(material),quaty(quaty)
- {
- cout << "父类Table有参构造函数" << endl;
- }
- //拷贝构造函数
- Table(const Table &other):material(other.material),quaty(other.quaty)
- {
- cout << "父类Table拷贝构造函数" << endl;
- }
- //拷贝赋值函数
- Table &operator=(const Table &other)
- {
- cout << "父类Table拷贝赋值函数" << endl;
- material=other.material;
- quaty=other.quaty;
- return *this;
- }
- ~Table()
- {
- cout << "父类Table析构函数" << endl;
- }
- void show()
- {
- cout << material <
- cout << quaty << endl;
-
- }
- };
- //封装 家具 沙发 桌子
- class Furni :public Sofa,public Table
- {
- private :
- int num ;
- string color;
- public:
- Furni(){cout << "子类无参构造函数" << endl;}
- Furni(int n,string c,string sit,string m,int q):Sofa(sit),Table(m,q),num(n),color(c)
- {
- cout << "子类有参构造函数" << endl;
- }
- //子类拷贝构造函数
- Furni(const Furni &other):num(other.num),color(other.color),Sofa(other),Table(other)
- {
- cout << "子类拷贝函数" << endl;
- }
- //子类拷贝赋值函数
- Furni &operator=(const Furni &other)
- {
- cout << "子类拷贝赋值函数" << endl;
- num=other.num;
- color=other.color;
- Sofa::operator=(other);
- Table::operator=(other);
- return *this;
- }
- ~Furni()
- {
- cout << "子类析构函数" << endl;
- }
-
-
- void show()
- {
- cout << num <
- cout << color << endl;
-
- }
-
- };
- int main()
- {
- Furni s(10,"white","可坐","woolen",20);
- Furni s1;
- Furni s2(s);
- s1=s;
- s.Sofa::show();
- s.Table::show();
- s.show();
- return 0;
- }


-
相关阅读:
PTA 7-72 成绩分析表
详解react生命周期和在父子组件中的执行顺序
马斯克发布人形机器人进展,它是否“中看不中用”?
MYSQL常用函数详解
天翎BPM流程引擎助力打造流程服务中台
STM32 HAL库 串口使用问题记录
论文阅读——RetNet
【Java EE】JUC(java.util.concurrent) 的常见类
网工内推 | 国企、上市公司,IA/IP认证即可,有年终、绩效
JAVA_多态(面向对象进阶)学习笔记
-
原文地址:https://blog.csdn.net/weixin_42019010/article/details/133777161