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 are the advantages of using a pointer?
What gives the current position of the put pointer?
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
Explain what you mean by a pointer.
What is difference between class and function?
What does override mean in c++?
What is the return value of the insertion operator?
Is c++ slower than c?
What are references in c++? What is a local reference?
What is the use of main function in c++?
What is abstraction with real time example?
Is turbo c++ free?
Is sorted c++?
Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
Specify some guidelines that should be followed while overloading operators?