I have a base class and I don't want the derived class to be copied. To make everything explicit, I implement it this way:
class A { public: A() = default; virtual ~A() = default; A(const A&) = delete; A(const A&&) = delete; A& operator=(const A&) = delete; A& operator=(const A&&) = delete; virtual void vFun() = 0; }; class B : public A { public: B() = default; virtual ~B() = default; B(const B&) = delete; B(const B&&) = delete; B& operator=(const B&) = delete; B& operator=(const B&&) = delete; virtual void vFun() override {} };
Is this the right way to do such things? According to my knowledge and what I read, the answer is yes, but I would like to be sure before introducing it into the production system.
EDIT
Introducing conclusions: 1) Almost always move operators should not be deleted. This is because "there is an infinity of things that require mobility." 2) For an abstract base class, it is safer to allow the compiler to generate a special member function and move the delete to the derived class if such a need exists.
source share