answersLogoWhite

0


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

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

Yes, although there are few practical reasons for doing so. The primary reason is to ensure only one instance of a class exists at all times (a singleton class). However, you must still provide some means of destroying the singleton, typically achieved via a static member function or a friend class or function.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are destructors in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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 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.


Is destructor allowed in java?

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


When was The Destructors - band - created?

The Destructors - band - was created in 1977.


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.


How do you describe the importance of destructors?

Destructors are used to free memory and release resources.


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

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


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

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


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?

4c


C plus plus uses dynamic memory management?

No, C++ does not use dynamic memory management. The programmer is entirely responsible for releasing dynamic memory when it is no longer required. When static objects fall from scope, their destructors are called automatically, but there is no automatic garbage collection for dynamic objects. Allocated memory remains allocated until the programmer manually releases it, or the thread that owns the memory is terminated.