工程上的多继承
被实际开发经验抛弃的多继承
工程开发中真正意义上的多继承是几乎不被使用的
多重继承带来的代码复杂性远多于其带来的便利
多重继承对代码维护性上的影响是灾难性的
在设计方法上,任何多继承都可以用单继承代替
多继承中的二义性和多继承不能解决的问题
class Parent{
public:
int getA(){
m_a = 10;
cout << "this is Parent getA()\n";
return m_a;
}
private:
int m_a;
};
class Interface1{
public:
virtual double add(double, double) = 0;
};
class Interface2{
public:
virtual double mul(double, double) = 0;
};
class Child :public Parent, public Interface1, public Interface2{
double add(double a, double b){
cout << "this is Child add()\n";
return a + b;
}
double mul(double a, double b){
cout << "this is Child mul()\n";
return a * b;
}
};
Main:
Interface1* t1;
Interface2* t2;
Child c;
c.getA();//this is Parent getA()
t1 = &c;
t1->add(10, 20);//this is Child add()
t2 = &c;
t2->mul(12, 13);//this is Child mul()