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
How do I exit turbo c++?
Incase of a function declaration, what is extern means?
What are literals in C++?
Is string an object in c++?
What is nested class in c++?
Should I learn c or c++ or c#?
Explain the purpose of the keyword volatile.
What does h mean in maths?
What is general form of pure virtual function? Explain?
How would you implement a substr() function that extracts a sub string from a given string?
Explain how functions are classified in C++ ?
Is c++ platform dependent?
What are pointer-to-members in C++? Give their syntax.
What is function overloading c++?
write a function signature with various number of parameters.