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

Tell me can a pure virtual function have an implementation?

1043


How can I disable the "echo" feature?

1179


Which operations are permitted on pointers?

1007


How to declare a pointer to an array of integers?

1148


What does it mean to declare a member function as virtual?

1084


How do you save a c++ program?

1049


Can you please explain the difference between using macro and inline functions?

1056


What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

1185


How the virtual functions maintain the call up?

1220


What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?

1203


Explain the term memory alignment?

1249


Is java made in c++?

1077


What is the maximum combined length of command line arguments including the space between adjacent arguments?

1010


What is the difference between a "copy constructor" and an "assignment operator" in C++?

1087


What is Destructor in C++?

1205