Need of privatizing assignment operator in a Singleton class

前端 未结 7 1027
一生所求
一生所求 2021-01-18 04:01

Can someone justify the need of privatizing the assignment operator in a Singleton class implementation?

What problem does it solve by making Singleton& o

7条回答
  •  春和景丽
    2021-01-18 04:30

    My reasoning is this: if only one instance may be around, operator= could be defined without problem, since it will not do anything significant. if we make it private, the compiler will add one more level of safety by flagging any attempt to use that operator as an error.

    The same reasoning holds for the destructor, by the way.

提交回复
热议问题