Have the assignment operator be callable on lvalues only:
class C
{
// ...
public:
C& operator=(const C&) & = default;
};
Note the single ampersand after the closing parenthesis. It prevents assigning to rvalues.
More Related Contents:
- Rule-of-Three becomes Rule-of-Five with C++11? [closed]
- What are the main purposes of using std::forward and which problems it solves?
- What does T&& (double ampersand) mean in C++11?
- C++11 rvalues and move semantics confusion (return statement)
- A positive lambda: ‘+[]{}’ – What sorcery is this? [duplicate]
- Rvalue Reference is Treated as an Lvalue?
- Move capture in lambda
- Do rvalue references to const have any use?
- Why is `std::move` named `std::move`?
- Syntax for universal references
- Is the pass-by-value-and-then-move construct a bad idiom?
- How to actually implement the rule of five?
- Why user-defined move-constructor disables the implicit copy-constructor?
- What’s a use case for overloading member functions on reference qualifiers?
- non-class rvalues always have cv-unqualified types
- In C++, what categories (lvalue, rvalue, xvalue, etc.) can expressions that produce temporaries of class type fall into?
- Is it possible to std::move objects out of functions? (C++11)
- Why do some people use swap for move assignments?
- Can I typically/always use std::forward instead of std::move?
- Is there actually a reason why overloaded && and || don’t short circuit?
- Can compiler generate std::move for a last use of lvalue automatically?
- On how to recognize Rvalue or Lvalue reference and if-it-has-a-name rule
- What are the main purposes of std::forward and which problems does it solve?
- Passing rvalues through std::bind
- C++11 rvalue reference calling copy constructor too
- Understanding rvalue references
- How does std::forward receive the correct argument?
- What is use of the ref-qualifier `const &&`?
- Is there a reference_wrapper for rvalue references?
- using declaration in variadic template