Implicit Move and Copy
suggest changeBear in mind that declaring a destructor inhibits the compiler from generating implicit move constructors and move assignment operators. Declaring a copy constructor or a copy-assignment operator does so as well. If you declare one of those, and the class should be movable, define the move operations too.
Furthermore, declaring move operations will suppress the generation of copy operations, so these should also be added (if the objects of this class are required to have copy semantics).
class Movable {
public:
virtual ~Movable() noexcept = default;
// compiler won't generate these unless we tell it to
// because we declared a destructor
Movable(Movable&&) noexcept = default;
Movable& operator=(Movable&&) noexcept = default;
// declaring move operations will suppress generation
// of copy operations unless we explicitly re-enable them
Movable(const Movable&) = default;
Movable& operator=(const Movable&) = default;
};
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents