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

What is istream c++?

1199


What things would you remember while making an interface?

1006


which operator is used for performing an exponential operation a) > b) ^ c) none

1065


What do you mean by const correctness?

1090


Why is main function important?

1112


Which function should be used to free the memory allocated by calloc()?

1026


Is c++ a good beginners programming language?

1078


Explain about Virtual Function in C++?

1030


What is the best c++ book?

1268


What is lambda expression c++?

1059


Search for: what is pair in c++?

1121


Explain selection sorting?

1084


Can you pass a vector to a function?

982


What are the storage qualifiers?

1163


What is nested class in c++?

964