answersLogoWhite

0

What value does destructor return?

Updated: 12/20/2022
User Avatar

Wiki User

10y ago

Want this question answered?

Be notified when an answer is posted

Add your answer:

Earn +20 pts
Q: What value does destructor return?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between the constructor to and destructor?

Functions and Constructors are similar in many ways. They can have arguments, they can have any amount of code, they can access the class's variables etc. the only difference is that a method in java needs to mandatorily have a return type but a Constructor in java cannot have a return type. It always creates and returns an object of the class for which it is the constructor. You cannot return a value from a constructor explicitly and if you try to do that, the compiler will give an error. The system knows that the purpose of the constructor is to create an object of the class and it will do the same irrespective of whether you declare a return type or not.


A method that is automatically called when an instance of a class is created?

The constructor of a class is automatically called when an instance of the class is created (using new in C++). The constructor method has the same name as the class that it is a part of. Constructors have no type and do not return anything. Similarly, the destructor is automatically called when the instance of the class is destroyed. The destructor is the same name as the class and is preceded by a tilde (~) For example: class Example { public: Example() // Constructor { printf("Object created\n"); } ~Example() // Destructor { printf("Object destroyed\n") } }; int main() { Example* x = new Example(); // Creates object, calls constructor delete x; // Calls destructor, deletes object return 0; }


What is the opposite of inventor?

destructor


Difference in using a method that return value and method that does not return value in object orinted programming?

A method that return a value should have a return statement. The method signature should indicate the type of return value. While in the case of a method that does not return a value should not have a return statement and in the signature, the return type is void. When using a method that doesn't return a value, a programmer can not get a value from that function, but instead, it can only change variable values and run other methods.


Can you overload destructor for your class?

No. Classes can only have one destructor, whether you define one yourself or allow the compiler to generate one for you. The compiler-generated destructor is public by default, does not release any memory allocated to any class' member pointers, and is non-virtual, which are the three main reasons for defining your own.

Related questions

Why destructure not have any return type?

I assume you mean "destructor". A destructor is invoked automatically, when an object is destroyed. It is not invoked as a method, as in: x = anObject.destroy(); The above is NOT the way a destructor is invoked; you have no control over the destruction process, can't assign a possible return value to any variable, so it makes no sense to HAVE a return value. Destructors (and constructors for that matter) are not implemented as functions. They are simply procedures and procedures have no return value, not even void. This makes sense because when an object reference falls from scope, its destructor must be called automatically. And in the case of derived objects, the virtual destructors must be called in sequence, from most-derived to least derived. Returning temporary values that would simply be destroyed anyway is somewhat pointless when all you want to do is invoke the destructor itself. Even if an object were instantiated dynamically (with the new() operator), and you subsequently deleted a pointer to one of the object's base classes, virtual destruction ensures the cascade of destructors happens in the correct sequence. But the delete() operator that invoked the destruction itself returns void. Again, returning values from destructors that would simply be temporary and therefore automatically fall from scope would make no sense. Ultimately, no return value makes any sense in a destructor (or a constructor, for that matter). Even a return value of void would make no sense.


What is the difference between the constructor to and destructor?

Functions and Constructors are similar in many ways. They can have arguments, they can have any amount of code, they can access the class's variables etc. the only difference is that a method in java needs to mandatorily have a return type but a Constructor in java cannot have a return type. It always creates and returns an object of the class for which it is the constructor. You cannot return a value from a constructor explicitly and if you try to do that, the compiler will give an error. The system knows that the purpose of the constructor is to create an object of the class and it will do the same irrespective of whether you declare a return type or not.


When was Varroa destructor created?

Varroa destructor was created in 2000.


Why pointer of constructor is made but not of destructor?

When a constructor is invoked dynamically, the new operator allocates the required memory, initialises it according to the constructor, then returns a pointer to the allocation. The destructor is invoked by deleting the pointer. It wouldn't make any sense to return a pointer from a deletion.


What is l drago destructor ultimate move?

Dragon Emperor Life Destructor.


A method that is automatically called when an instance of a class is created?

The constructor of a class is automatically called when an instance of the class is created (using new in C++). The constructor method has the same name as the class that it is a part of. Constructors have no type and do not return anything. Similarly, the destructor is automatically called when the instance of the class is destroyed. The destructor is the same name as the class and is preceded by a tilde (~) For example: class Example { public: Example() // Constructor { printf("Object created\n"); } ~Example() // Destructor { printf("Object destroyed\n") } }; int main() { Example* x = new Example(); // Creates object, calls constructor delete x; // Calls destructor, deletes object return 0; }


What does instructor rhyme with?

Destructor


What is the opposite of inventor?

destructor


What are the characteristics of a destructor?

The main characteristics of a Destructor are:Are inverse of ConstructorsCalled when objects are destroyedUsed to unlink an object resource / clean up resources used by an instance of a classAutomatically called when the instance of the class goes out of scopeDoesn't return any valueHas the same name as that of the class with a special character infront ( like ~ in C++ )


What actors and actresses appeared in El destructor - 1985?

The cast of El destructor - 1985 includes: Eduardo Palomo


Difference in using a method that return value and method that does not return value in object orinted programming?

A method that return a value should have a return statement. The method signature should indicate the type of return value. While in the case of a method that does not return a value should not have a return statement and in the signature, the return type is void. When using a method that doesn't return a value, a programmer can not get a value from that function, but instead, it can only change variable values and run other methods.


Can you overload destructor for your class?

No. Classes can only have one destructor, whether you define one yourself or allow the compiler to generate one for you. The compiler-generated destructor is public by default, does not release any memory allocated to any class' member pointers, and is non-virtual, which are the three main reasons for defining your own.