My question is in reference to the following links:
Why declare a deleted assignment operators with the ref-qualifier &
Should I use lvalue reference qualifiers for assignment operators?
I could not follow the posts. Could somebody explain:
- What does the
&
at the end in the given code snippet actually do?auto operator=(const string& rhs) &;
. - Why does the
&
at the end of this given code snippet is redundant? (Please also confirm if its just redundant or it is problematic)auto operator=(const string& rhs) & = delete;
- Is this statements is valid,
auto operator=(const string&& rhs) &&;
?
If qualifier &
prevents copy assignment of rvalue, Is it not already taken care by the type of input parameter specified? (const string& rhs
).
In the following example, with or without qualifier, I get same result for rvalue assignment.
class copy_assignment{
public:
copy_assignment& operator=(copy_assignment& a) & {cout << "copied"; return a;};
copy_assignment* get_ca(){return new(copy_assignment);}
};
int main()
{
copy_assignment a, b;
a = *b.get_ca();
}