#include <iostream>
//多继承
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 <<endl;
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 <<endl;
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;
}