Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 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
Nov 21, 2002
16
What is the relationship between constructor and function?Is it necessary to create destructor whenever we create constructor?
 
Replies continue below

Recommended for you

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