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 to access grid view row?

2283


What are the advantages of c++? Explain

1114


How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?

2367


What is the difference between a definition and a declaration?

1112


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

1201


What do you understand by pure virtual function? Write about its use?

1044


Explain 'this' pointer and what would happen if a pointer is deleted twice?

1130


What are containers in c++?

1031


Is it possible to provide special behavior for one instance of a template but not for other instances?

1172


Should a constructor be public or private?

1086


What is virtual base class?

1131


What is iterator c++?

1036


How many types of scopes are there in c++?

1167


Define 'std'.

1223


write a corrected statement so that the instruction will work properly. if (4 < x < 11) y = 2 * x;

2055