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

How do I exit turbo c++?

1002


Incase of a function declaration, what is extern means?

902


What are literals in C++?

978


Is string an object in c++?

1104


What is nested class in c++?

895


Should I learn c or c++ or c#?

951


Explain the purpose of the keyword volatile.

1102


What does h mean in maths?

1106


What is general form of pure virtual function? Explain?

941


How would you implement a substr() function that extracts a sub string from a given string?

993


Explain how functions are classified in C++ ?

1178


Is c++ platform dependent?

1035


What are pointer-to-members in C++? Give their syntax.

1081


What is function overloading c++?

1020


write a function signature with various number of parameters.

989