Virtual destructor for boost:noncopyable classes?
boost, c++, noncopyable
Solution
No, the entire point of a virtual destructor is so derived classes can properly destruct polymorphically. If this will never be a base class, you don't need it to be virtual.
Problem
I have a question about the following code: ``` class MyClass : private boost::noncopyable { public: MyClass() {} virtual ~MyClass() {} } class OtherClass : private boost::noncopyable { private: MyClass* m_pMyClass; } ``` My thoughts are that MyClass cannot be copied using construction or assignment. Using a virtual destructor is needed if I want to support deriving classes from MyClass, which I do not want to support. I do not intend to create pointers to this class and pass them around. I do not want a Singleton and I cannot see a downside to removing the virtual destructor. Do I introduce a potential problem if remove the virtual destructor for a noncopyable class? Are there a better practices to handle a class that does not need to be a Singleton, but I only want one instance in another class and not support inheritance?