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

Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);

1117


Why are pointers not used in c++?

1191


What new()is different from malloc()?

1162


Which software is best for c++ programming?

1091


How is new() different from malloc()?

1179


Why isn't sizeof for a struct equal to the sum of sizeof of each member?

1059


What is c++ & why it is used?

1157


what is c++

2432


Does there exist any other function which can be used to convert an integer or a float to a string?

1133


What are the differences between new and malloc?

1201


Write a program which uses functions like strcmp(), strcpy()? etc

1156


What is function declaration in c++ with example?

1183


What is the latest c++ standard?

1193


On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?

1184


Is dev c++ free?

1101