I have seen that constructors, copy constructor, destructor and assignment operator is kept in private scope in a typical singletone class. e.g.
class CMySingleton
{
public:
static CMySingleton& Instance()
{
static CMySingleton singleton;
return singleton;
}
private:
CMySingleton() {} // Private constructor
~CMySingleton() {}
CMySingleton(const CMySingleton&); // Prevent copy-construction
CMySingleton& operator=(const CMySingleton&); // Prevent assignment
};
Now, my question is
why shoule we keep destructor and assignment operator in private scope? Is it mandatory?
Does a public destructor break any property of a singleton class? Because since our object construction is restricted so there is no chance of a unwanted destruction.
I can understand that private assignment operator can prevent a self assignment, but does a public assignment operator harm anyway other than extra run-time?