0

Can anyone tell me how to create an object of a private constructor in c++

16th Jul 2022, 11:20 PM
Abdul Rahim
Abdul Rahim - avatar
2 Answers
+ 3
As soon as a constructor is moved under private section of the class, only a friend class or a member function can access it. There are 2 use case of the same that I can think of. 1) in singleton design pattern: where you use a static member function of the class to create/get an instance of the class object. 2) when we want to restrict the object creation to a friend class only.
17th Jul 2022, 12:55 AM
Arsenic
Arsenic - avatar
+ 1
Thankyou
17th Jul 2022, 6:13 AM
Abdul Rahim
Abdul Rahim - avatar