相关疑难解决方法(0)

需要在Singleton类中私有化赋值运算符

有人可以证明在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
};
Run Code Online (Sandbox Code Playgroud)

c++ singleton assignment-operator

7
推荐指数
1
解决办法
4429
查看次数

标签 统计

assignment-operator ×1

c++ ×1

singleton ×1