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...

Do we have private destructors?

Answer Posted / sampurna pandey

yes, we can have both private constructor and destructor
and can use them with help of static function for example

class Base
{
static int i;
Base(){}
~Base(){}
public:
static Base *Creat_Object();
static void Destroy_Object(Base *p);
void Add()
{
cout<<i<<" Add function"<<endl;
}
};

int Base::i=0;
Base* Base::Creat_Object()
{
Base * ptr = new Base();
i=5;
return ptr;
}

void Base::Destroy_Object(Base *p)
{
delete p;
}

void main()
{
Base *temp = Base::Creat_Object();
temp->Add();
Base::Destroy_Object(temp);
}

correct me if i am wrong.

Is This Answer Correct ?    21 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by persistent and non persistent objects?

1437


What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.

1067


What is stl containers in c++?

1051


What methods can be overridden in java?

1274


What are arrays c++?

1112


What is meant by the term name mangling in c++?

963


What are the five basic elements of a c++ program?

1114


What do you understand by a pure virtual member function?

1011


Will the following program execute?

1040


Explain this pointer?

1073


Is java the same as c++?

998


what is C++ exceptional handling?

1180


Why was c++ made?

1109


What are c++ data types?

1170


Difference between delete and free.

1081