我给下面的例子来说明我的问题:C++拷贝赋值运算符的参考对象变量
class Abc
{
public:
int a;
int b;
int c;
};
class Def
{
public:
const Abc& abc_;
Def(const Abc& abc):abc_(abc) { }
Def& operator = (const Def& obj)
{
// this->abc_(obj.abc_);
// this->abc_ = obj.abc_;
}
};
在这里,我不知道如何定义拷贝赋值运算符。你有什么想法?谢谢。
无法完成。如果你想让'Def'赋值,让它包含一个指针,而不是引用。 – Quentin
^^^案例和观点:['std :: reference_wrapper'](http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper) – StoryTeller
您*可以*使用复制构造函数来实现结果你要。但是你不能完成任务,因为参考成员只能在施工期间设置。 – 0x5453