+ 1
Constructor
is constructor always public?
4 Respostas
+ 1
In singleton design pattern , we have constructor as private
0
If you want to create object of given class- yes.
But sometimes when you do not want to create object, you may make it private.
(I wrote a code in which class has private ctor)
https://code.sololearn.com/cub4oA2riU4b/?ref=app
0
@Vignesh can you give source of such an implementation of Singleton? Everyone and every site I've been learning from told me that ctor in singleton is private.
0
sorry @jakub stasiak typo error it is Private..
link :
http://www.yolinux.com/TUTORIALS/C++Singleton.html
if you want to prevent your object from being copied you have to declare the constructor as private.