+ 10
Can we have private constructors in c++? If yes, what is the use of it?
4 Answers
+ 9
Thank you all
+ 7
Yes
+ 2
For creating an object of that class within the class itself
+ 1
Sample uses (there are others):
- Several overloaded public constructors can forward-call a private constructor to implement constructor functionality after doing some type conversions.
- A public factory method can call a private constructor to control creation of this class's objects.