Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.

1115


What is array in c++ pdf?

1185


program explaining feautures of c++

2436


What is an associative container in c++?

1067


What is stoi in c++?

1179


Explain virtual class and friend class.

1046


What is the difference between a definition and a declaration?

1069


What are the uses of static class data?

1185


Can we overload operator in c++?

1036


What is std :: endl?

1031


What is recursion?

2168


What is a hashmap c++?

1121


write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)

2378


How to defines the function in c++?

1129


What are friend classes?

1064