Share
Go down
avatar
Admin
Posts : 7
Join date : 2018-08-07
View user profilehttp://jenreyes.forumotion.com

Destructors

on Wed Aug 08, 2018 2:42 pm
A destructor contains the actions you require when an instance of a class is destroyed. Most often, an instance of a class is destroyed when the object goes out of scope. For example, when an object is declared within a method, the object goes out of scope when the method ends. As with constructors, if you do not explicitly create a destructor for a class, one is provided automatically.

The most common way to declare a destructor explicitly is to use an identifier that consists of a tilde (~) followed by the class name. You cannot provide parameters to a destructor; it must have an empty parameter list. As a consequence, destructors cannot be overloaded; a class can have only one destructor. Like a constructor, a destructor has no return type.


Employee class with destructor


Last edited by Admin on Mon Aug 20, 2018 2:08 pm; edited 1 time in total
Guru
Guru
Posts : 10
Join date : 2018-08-08
View user profile

Re: Destructors

on Wed Aug 08, 2018 4:15 pm
does a destructor must have an empty parameter list?
Guru
Guru
Posts : 10
Join date : 2018-08-08
View user profile

Re: Destructors

on Wed Aug 08, 2018 4:16 pm
Unlike constructors, you must explicitly create a destructor if you want one for a
class.
Guru
Guru
Posts : 10
Join date : 2018-08-08
View user profile

Re: Destructors

on Wed Aug 08, 2018 4:17 pm
additional info: Destructors cannot be overloaded; a class can have only one destructor.
Guru
Guru
Posts : 10
Join date : 2018-08-08
View user profile

Re: Destructors

on Wed Aug 08, 2018 4:48 pm
Anna06 wrote:Unlike constructors, you must explicitly create a destructor if you want one for a
class.
that's not true as with constructors, if you do not explicitly create a destructor for a class, one is provided automatically.
Guru
Guru
Posts : 10
Join date : 2018-08-15
View user profile

Re: Destructors

on Wed Aug 15, 2018 4:40 pm
what is the difference between destructor and constructor?
Guru
Guru
Posts : 10
Join date : 2018-08-15
View user profile

Re: Destructors

on Wed Aug 15, 2018 4:41 pm
What is the importance of constructor and destructor in C++?
Guru
Guru
Posts : 10
Join date : 2018-08-15
View user profile

Re: Destructors

on Wed Aug 15, 2018 4:41 pm
What is the use of the destructor?
Sponsored content

Re: Destructors

Back to top
Permissions in this forum:
You cannot reply to topics in this forum