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
Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.
What is array in c++ pdf?
program explaining feautures of c++
What is an associative container in c++?
What is stoi in c++?
Explain virtual class and friend class.
What is the difference between a definition and a declaration?
What are the uses of static class data?
Can we overload operator in c++?
What is std :: endl?
What is recursion?
What is a hashmap c++?
write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)
How to defines the function in c++?
What are friend classes?