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 pre-processor in C++?

1154


Write about the role of c++ in the tradeoff of safety vs. Usability?

1061


Is map sorted c++?

997


Is c++ a dying language?

1144


Write about the retrieval of n number of objects during the process of delete[]p?

1018


What is the use of lambda in c++?

1018


What are the characteristics of friend functions?

1011


What are all predefined data types in c++?

1121


What is a static member?

1040


What is pair in c++?

1063


Define a constructor?

1045


When there is a global variable and local variable with the same name, how will you access the global variable?

1094


What does std :: flush do?

1130


Do you know what are pure virtual functions?

1143


What is c++ map?

1153