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 pre-processor in C++?
Write about the role of c++ in the tradeoff of safety vs. Usability?
Is map sorted c++?
Is c++ a dying language?
Write about the retrieval of n number of objects during the process of delete[]p?
What is the use of lambda in c++?
What are the characteristics of friend functions?
What are all predefined data types in c++?
What is a static member?
What is pair in c++?
Define a constructor?
When there is a global variable and local variable with the same name, how will you access the global variable?
What does std :: flush do?
Do you know what are pure virtual functions?
What is c++ map?