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
What is istream c++?
What things would you remember while making an interface?
which operator is used for performing an exponential operation a) > b) ^ c) none
What do you mean by const correctness?
Why is main function important?
Which function should be used to free the memory allocated by calloc()?
Is c++ a good beginners programming language?
Explain about Virtual Function in C++?
What is the best c++ book?
What is lambda expression c++?
Search for: what is pair in c++?
Explain selection sorting?
Can you pass a vector to a function?
What are the storage qualifiers?
What is nested class in c++?