【发布时间】:2020-11-11 05:55:08
【问题描述】:
有没有区别
class MyString {
...
MyString &operator=(MyString other) {
swap(s, other.s);
return (*this);
}
};
和
class MyString {
...
MyString &operator=(MyString other) {
swap(s, other.s);
return *this;
}
};
我在其他一些posts 中读到,添加括号表示您通过引用而不是值返回。但是如果定义了返回类型,它似乎并没有什么不同。
【问题讨论】:
-
在您的情况下,附加括号没有任何区别。使用你喜欢的任何编码风格。