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

Can the creation of operator** is allowed to perform the to-the-power-of operations?

1002


Why c++ is better than c language?

1020


What is the full name of logo?

1124


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

1325


Can constructor be private in c++?

1042


What is stream and its types in c++?

1056


What are the uses of typedef in a program?

1086


What is extern c++?

1005


Why is c++ still used?

1091


What operator is used to access a struct through a pointer a) >> b) -> c) *

1120


Why do we use constructor?

1059


How much do coding jobs pay?

1013


What are c++ manipulators?

1079


To what does “event-driven” refer?

1058


Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

1001