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 / binoy mathew

#include <iostream>
#include <stdlib.h>

class t
{
public:
t()
{
printf("in constr");
}

private: // note that constructor is private here
~t()
{
printf("in destr");
}
};


int main()
{
t *t1 = new t; // create a new obj
delete t1; // delete the obj, which calls destructor
return 0;
}

Try to compile the above code.
following error results...

[root@localhost Desktop]# g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:13: error: ‘t::~t()’ is private
tt.cpp:: error: within this context
[root@localhost Desktop]#

....implies, we can't have destructor private.

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between public, private, and protected access?

1134


Why do we need templates?

1052


what does the following statement mean? int (*a)[4]

1139


If there are two catch statements, one for base and one for derived, which should come first?

1083


Tell me an example where stacks are useful?

1101


Why do we use the using declaration?

1237


What is the keyword auto for?

1090


Is java easier than c++?

1076


Which of the following is evaluated first: a) && b) || c) !

2421


Should I learn c or c++ first?

1180


What is the history of c++?

1137


Which compiler does turbo c++ use?

1140


What is a flag in c++?

1110


When to use “const” reference arguments in a function?

1127


What is constant in c++ with example?

1211