提问人:Stefan Nastase 提问时间:1/5/2021 最后编辑:Stefan Nastase 更新时间:1/5/2021 访问量:137
菱形继承的复制赋值运算符 C++
Copy assignment operator for diamond inheritance C++
问:
我在钻石继承层次结构中有 4 个类。在课堂上称呼父母双方的作业操作员为作业操作员是否正确?它不会调用运算符= 2次吗?有没有更好的方法?der12
base
protected:
int a = 1;
public:
base& operator=(const base& ref){
...
}
};
class der1 : virtual public base{
protected:
int b = 2;
public:
der1& operator=(const der1& ref){
...
}
};
class der2 : virtual public base{
protected:
int c = 3;
public:
der2& operator=(const der2& ref){
...
}
};
class der12 : public der1, public der2{
int d = 4;
public:
der12& operator=(const der12& ref){
der1::operator=(ref);
der2::operator=(ref);
d = ref.d;
return *this;
}
};```
答: 暂无答案
下一个:构造函数和赋值运算符行为
评论
der12
der1
der2
der1
der2