Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the relationship between co

Status
Not open for further replies.

lila

Civil/Environmental
Joined
Nov 21, 2002
Messages
16
Location
US
What is the relationship between constructor and function?Is it necessary to create destructor whenever we create constructor?
 
A constructor is a function that:
*Has no return value
*Is implicitly called when an object of that particular class is created

It is generally good practice to have a destructor, even if you don't do anything in it.

A destructor is necessary if you have any memory in the object that needs deallocation (e.g. arrays created with the new operator), or if there are things that need to be done before the object goes away (rerouting the links in a linked list comes to mind).

When the object is destroyed, the destructor is implicitly called and will perform any statements within the destructor (where you can call delete[], for instance)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top