I have a problem dealing with deprecated since C++11 default generation of copy constructor and copy assignment operator when there is a user-defined destructor.
For most sufficiently simple classes default-generated constructors, operators and destructor are fine. Consider the following reasons to declare destructor:
Making trivial destructor virtual in base class:
// header class Base1 { public: virtual ~Base1() = default; }; class Base2 { public: virtual ~Base2(); }; // source Base2::~Base2() = default;Would all 4 copy and move special methods be generated by compiler in these cases? If yes, then I think it is fine and there is no need to complicate
Base1orBase2.Printing debug message in destructor:
// header class D { public: ~D(); }; // source D::~D() { #ifdef DEBUG_THIS std::cout << "D was destructed." << std::endl; #endif }I believe that in this case copy constructor and assignment operator would be generated; but move constructor and assignment operator would not. I want to avoid using deprecated default-generating and disable copying of
D. I also want to avoid floodingDwith 4deleteddeclarations. Is disabling only one copy constructor enough? Is it a good style?
boost::noncopyable. With Visual C++ you might consider a macro that adds private declarations, to avoid sillywarnings. - Cheers and hth. - Alf