Programming Logic and Design
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
Admin
Admin
Admin
Posts : 7
Join date : 2018-08-07
https://jenreyes.forumotion.com

Destructors Empty Destructors

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.

Destructors Sa10

Employee class with destructor
Destructors Sa10


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

Destructors Empty Re: Destructors

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

Destructors Empty Re: Destructors

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

Destructors Empty Re: Destructors

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

Destructors Empty Re: Destructors

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.
avatar
Pamela16
Guru
Guru
Posts : 10
Join date : 2018-08-15

Destructors Empty Re: Destructors

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

Destructors Empty Re: Destructors

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

Destructors Empty Re: Destructors

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

Destructors Empty Re: Destructors

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