How to avoid a class from instantiation?
Answer Posted / maniac_2004
if you want to construct a class whos constructor is private
then use a static method which constructs the object and
returns the pointer
class A
{
private: A();
public:
static A * createInstance();
};
A* A::getInstance()
{
return new A();
}
main(){ A::createInstance();}
This is similar to the "singleton" pattern...
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why do we learn c++?
In c++, what is the difference between method overloading and method overriding?
What is a pointer how and when is it used?
What is the function to call to turn an ascii string into a long?
What is virtual base class?
What is overloading unary operator?
What is string in c++ programming?
What is a singleton c++?
Is facebook written in c++?
What is the difference between the compiler and the preprocessor?
What are features of c++?
What is nested class in c++?
What is the oldest programming language?
What is enum class in c++?
Does dev c++ support c++ 11?