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 do c++ programmers do?

1012


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

1036


What is the extension of c++?

926


What is the difference between cin.read() and cin.getline()?

1015


Which one is a preferred language C or C++? Why?

1023


Can we run c program in turbo c++?

1041


What is a static element?

1016


Does c++ have foreach?

979


Is c# written in c++?

922


what are the events occur in intr activated on interrupt vector table

1667


Write about the access privileges in c++ and also mention about its default access level?

1007


What is the difference between strcpy() and strncpy()?

1070


What is function prototyping? What are its advantages?

1031


What are the uses of static class data?

1119


What is the purpose of ios::basefield in the following statement?

1198