Best Answer

A destructor in C++ is a method of a class that runs when the class is deleted. It performs cleanup of the members of the class that need cleanup, such as deallocation of subobjects referred to by pointers in the class, subobjects which were earlier allocated by a constructor or other method of the class.

User Avatar

Wiki User

โˆ™ 2010-02-20 13:25:28
This answer is:
User Avatar
Study guides
See all Study Guides
Create a Study Guide

Add your answer:

Earn +20 pts
Q: What are destructors in c plus plus?
Write your answer...
Still have questions?
magnify glass
Related questions

Does c language really supports destructors?

it doesnt support destructors

What are the various concepts of c plus plus?

1.Classes and Objects 2.Constructors and Destructors 3.Inheritance 4.Polymorphism 5.Dynamic Binding

What is destructors in java?

No destructors in Java. The reason is that all Java objects are heap allocated and garbage collected. Without explicit deallocation (i.e. C++'s delete operator) there is no sensible way to implement real destructors.

Is destructor allowed in java?

No. Java does not support the concept of Destructors like C

What is the difference between destructors in c plus plus and c sharp?

In C# only class instances can have a destructor, whereas both class and struct instances can have a destructor in C++. While syntactically similar, a C++ destructor executes exactly as written, whereas a C# destructor merely provides the body of the try clause of the class' finalize method.

Can destructors be declared as static in c plus plus?

No -- it would make no sense to have a static destructor. Static members are local to the class. You cannot destroy a class, only an instance of a class, an object. Objects have no static members.

What are the main problem in constructor and destructor in c plus plus?

There are no problems with constructors or destructors in C++. Any problems encountered are a result of the code you write, not a result of the language. Constructors exist purely to initialise an object in a consistent manner while destructors exist to allow an instance of a class to clean up any dynamic memory allocations. If you use them for any other purpose then there's a clear design flaw in your class.

Who wrote the book The Destructors?

The Destructors was written by Graham Greene.

When was The Destructors - band - created?

The Destructors - band - was created in 1977.

What is c plus language?

There is no language called c plus. There is c, and there is c plus plus, but no c plus.

What literary classification does the Destructors fall under?

The Destructors is classified as a short story.

How do you describe the importance of destructors?

Destructors are used to free memory and release resources.

What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c

What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c

When destructors are called in c plus plus?

Destructors are called when an object falls from scope, or by deleting a pointer to an unreferenced object (references can never be NULL so don't delete them via pointers -- they will destroy themselves when they fall from scope). If the object is derived, the call cascades up the inheritance hierarchy to destroy the underlying classes in the reverse order they were created, from the most-derived (your object) to the least-derived (the base class(es)).

B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c

Symplify c plus c plus c plus c?


B plus b plus c plus c plus c plus c equals?


What are the books to study C Plus Plus?

One book to study C Plus Plus is "C Plus Plus for Dummies." Another book to study C Plus Plus is "C Plus Plus Primer".

What do you mean by finalizer method?

In C++ you have object constructors and object destructors. Both are called by the developer. In Java and C# you have constructors and finalizer methods, so Java and C# both have support for finalizer methods (also known simply as finalizer). So the finalizer methods are similar to the destructors of C++ with a very important twist, the finalizer method is called by the garbage collector when an object is freed and not by the programmer (like the destructors in C++). Both finalizers in Java, C# and destructors in C++ can be used to free resources such as sockets or file handles that the method is using. However, because the finalizer methods are called by the garbage collector the programmer has no control of when the finalizer method will be called. As such it is NOT A GOOD IDEA to use finalizer methods. One can write the methods of an object in such a way as to clean up after themselves.

What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.

Primary and secondary key in c and c plus plus?

There are no "primary and secondary keys" in c and c plus plus.

Symbolism in destructors?

the people

What is c plus C plus C answer in algebra?


What is b plus b plus b plus c plus c plus c plus c in algebra?

It is the same as: 3b+4c which is an algebraic expression