什么& =在C& operator =(const C&)& =默认;做? [英] What does & = in C& operator=(const C&) & = default; do?
本文介绍了什么& =在C& operator =(const C&)& =默认;做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SO的几个问题使用特定语法来声明默认赋值运算符。
class C {
C(const C&)= default;
C(C&&)= default;
C& operator =(const C&)& =默认;
C& operator =(C&& amp;)& =默认;
virtual〜C(){}
};
=用于赋值运算符。经过快速测试,默认赋值运算符声明似乎编译并给出了带或不带附加&符号的预期行为。
我看不到& c> c>
在这种特殊情况下,它使得你想分配给C的实例必须是一个非常量的值。
A few questions on SO use a particular syntax for declaring default assignment operators.
Rule-of-Three becomes Rule-of-Five with C++11?
class C {
C(const C&) = default;
C(C&&) = default;
C& operator=(const C&) & = default;
C& operator=(C&&) & = default;
virtual ~C() { }
};
I'm confused by the & = used for the assignment operators. After a quick test, default assignment operator declarations seem to compile and give the expected behavior with or without the additional ampersand.
I don't see the & = syntax on cppreference.
解决方案
The &
there is a ref qualifier.
In that particular case it makes it so that the instance of C you want to assign to must be a non-const lvalue.
这篇关于什么& =在C& operator =(const C&)& =默认;做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文