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
Tell me can a pure virtual function have an implementation?
How can we read/write Structures from/to data files?
Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.
What does ctime() do?
What's the best free c++ profiler for windows?
What is constructor c++?
How does c++ structure differ from c++ class?
Which one is a preferred language C or C++? Why?
Write about an iterator class?
What is c++ 11 and c++ 14?
In what situations do you have to use initialization list rather than assignment in constructors?
What is iostream in c++ used for?
What is a node class in c++?
What does h mean in maths?
How do I use turbo c++?