【发布时间】:2020-02-18 21:14:29
【问题描述】:
我想知道赋值运算符的默认实现是否检查自赋值,那么这两个实现中的哪一个可以被认为最接近默认实现:
class A{
int x;
public :
...
// first one
A& operator=(const A& a){
if(this != &a) x = a.x;
return *this;
}
// second one
A& operator=(const A& a){
x = a.x;
return *this;
}
}
我已经搜索过 C++ 标准,但我能找到的唯一一个是 this,但对此一无所知
【问题讨论】: