Need of privatizing assignment operator in a Singleton class

前端 未结 7 956
一生所求
一生所求 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:40

    Making the assignment operator private doesn't really change anything, since you need two instances to be able to assign. It does correspond to what people may expect to see; it's usual that if the copy constructor is private, the assignment operator is as well. Declaring a private assignment operator simply corresponds to people's expectations.

提交回复
热议问题