问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/24484365/what-does-in-c-operator-const-c-default-do