提问人:Amelio Vazquez-Reina 提问时间:1/1/2023 更新时间:1/1/2023 访问量:51
返回 const [duplicate] 的复制赋值运算符的用例
Use cases of a copy assignment operator that returns const [duplicate]
问:
我见过定义复制赋值运算符以返回引用的代码,例如const
const MyClass & operator= (const MyClass &);
我对意图以及如何使用这样的运算符感到困惑。
例如,假设我用它来做一些类似 ( and are objects of ) 的事情。这难道不需要声明为 ,如果是这样,那岂不是意味着我不能修改吗?(即有什么意义?a = b
a
b
MyClass
a
const
a
答: 暂无答案
评论
const
a=b
a
const
a
const
a = b;
a
const
b
const
const
const
void print(const std::string& str)
const
std::string