- #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;
- }


-
相关阅读:
以JSP为视图解析器搭建SSM项目
十一、2023.10.5.计算机网络(end).11
hadoop配置文件自检查(解决常见报错问题,超级详细!)
POJ3268最短路径题解
CRM自动化意味着什么?企业如何从中受益?
JS手机号码正则
IPEmotion曲线平滑计算
grafana 配置自定义dashboard
git分布式管理-头歌实验合并远程分支、rebase、储藏
万界星空科技商业开源MES
-
原文地址:https://blog.csdn.net/weixin_42019010/article/details/133777161