I began learning c++ language. I want to know about private constructor. So please tell me about use of private constructor in C++. Any help will be appreciated.
I began learning c++ language. I want to know about private constructor. So please tell me about use of private constructor in C++. Any help will be appreciated.
Private constructor is utilized in c++ to make object of class single time. Means your class doesn’t have more that one instance of class. See code given below to understand it.
Code:class MyClassEg() { private: MyClassEg() { } public: MyClassEg & Instances() { static MyClassEg * aGlobalInsts = new MyClassEg(); return *MyClassEg; } };
Bookmarks