Top Answer
User Avatar
Wiki User
Answered 2010-02-20 13:25:28

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

Your Answer

Related Questions

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

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.

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.

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

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.

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.

The Destructors was written by Graham Greene.

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

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.

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)).

The Destructors is classified as a short story.

Destructors are used to free memory and release resources.

The Destructors - band - was created in 1977.

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

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".

A destructor should be declared virtual when the class is intended to be used as a base class. Not all classes are intended as base classes thus destructors are non-virtual by default. Derived classes do not need to declare virtual destructors as they can be declared with override (C++11). The reason base class destructors are declared virtual is to ensure that the class hierarchy is destroyed in the reverse order it was constructed, starting with the most-derived class destructor (regardless of which object in the hierarchy falls from scope first). If we don't declare the destructor virtual, we cannot guarantee the most-derived class will be destroyed first, which could leave a partial object in memory and thus create a resource leak.

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

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

The central differences between Java and C++ are:Memory Management: Java is a memory-managed language, meaning that it uses automatic garbage collection. C++ programmers have to take care of memory issues themselves.Destructors: As a result, Java does not need destructors to do memory cleanup, so it does not have destructors.Inheritance: Java does not allow multiple inheritance. It has interfaces as a partial substitute to C++'s multiple inheritance.Objects: Every non-primitive variable in Java is an object. Java has no "free functions" that are out of the scope of a class or object.JVM: Java is built on the concept of using a virtual machine, the JVM. C++ is planned to be compiled to native machine code. This makes Java more portable and more secure. OTOH, this makes C++ faster than Java, but this is only noticeable in heavy-computation programs.Java is pure object oriented language, and C++ is not, because you can access the private member of classes in c++ by using the friend function. There is no such function within java.

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

There are no such things as 'Windows C++' and 'Linux C++'

Copyright ยฉ 2021 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.