Puedes seguirnos en

BUSCADOR

Engineering

Destructors in a class in C++

Destructors is used to destroy the objects that have been created by a constructor. The destructor is member function whose name is the same as of the class, but it is preceded by tilde(~).

For example the destructors for the class integer can be defined as shown below:
~integer() {}

A destructor never takes any arguments nor does it return any value. It will be invoked implicitly by compiler upon exit from the program(or block or function as the case may be) to clean up storage that is no longer accessible.

It is good practice to declare destructors in a program since it releases memory space for future use. Whenever new operator is used to allocate memory in constructor, we should use delete to free that memory. This is required because when the pointer to object goes out of scope, destructors is not called implicitly.

Anuncio publicitario

Escrito por

Administrador de ENGGDRCAOS. Canal dedicado especialmente a la formación del estudiante que aspira a ser ingeniero. Todos los videos son Ingles. Apasionado del universo Apple, estudiante de Ingeniería y Gamer por vocación.

Publicidad

ARTÍCULOS RELACIONADOS

Engineering

Function prototyping is one of the key improvements added to the C++ functions. When a function call is encountered, the compiler checks the function...

Engineering

Inheritance is not just simply about creating various derived classes trough a base class. There are some other benefits of using Inheritance in Object...

Engineering

When virtual functions are created for implementing late binding, there are some basic rules that satisfy the compiler requirements: The virtual function must be...

Engineering

Data types are specifications provided with the variable or function name. These data type are categorized into three types as follows.