有人可以证明需要在 Singleton 类实现中私有化赋值运算符吗?
Singleton& operator=(Singleton const&);
私有化解决了什么问题?
class Singleton {
public:
static Singleton& Instance() {
static Singleton theSingleton;
return theSingleton;
}
private:
Singleton(); // ctor hidden
Singleton(Singleton const&); // copy ctor hidden
Singleton& operator=(Singleton const&); // assign op. hidden
~Singleton(); // dtor hidden
};