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.
Employee class with destructor
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
- Anna06Guru
- Posts : 10
Join date : 2018-08-08
Re: Destructors
Wed Aug 08, 2018 4:15 pm
does a destructor must have an empty parameter list?
- Anna06Guru
- Posts : 10
Join date : 2018-08-08
Re: Destructors
Wed Aug 08, 2018 4:16 pm
Unlike constructors, you must explicitly create a destructor if you want one for a
class.
class.
- Anna06Guru
- Posts : 10
Join date : 2018-08-08
Re: Destructors
Wed Aug 08, 2018 4:17 pm
additional info: Destructors cannot be overloaded; a class can have only one destructor.
- GraceAnnGuru
- Posts : 10
Join date : 2018-08-08
Re: Destructors
Wed Aug 08, 2018 4:48 pm
that's not true as with constructors, if you do not explicitly create a destructor for a class, one is provided automatically.Anna06 wrote:Unlike constructors, you must explicitly create a destructor if you want one for a
class.
- Pamela16Guru
- Posts : 10
Join date : 2018-08-15
Re: Destructors
Wed Aug 15, 2018 4:40 pm
what is the difference between destructor and constructor?
- Pamela16Guru
- Posts : 10
Join date : 2018-08-15
Re: Destructors
Wed Aug 15, 2018 4:41 pm
What is the importance of constructor and destructor in C++?
- Pamela16Guru
- Posts : 10
Join date : 2018-08-15
Re: Destructors
Wed Aug 15, 2018 4:41 pm
What is the use of the destructor?
Permissions in this forum:
You cannot reply to topics in this forum
|
|