answersLogoWhite

0


Best Answer

A more pertinent question is why would you need to? The destructor exists purely to clean up any memory allocated to the class instance variables. If the destructor requires a "parameter" to do so, then there's a clear design flaw in the class. The class is perfectly capable of cleaning up its own instance variables without any need for a parameter.

User Avatar

Wiki User

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

Wiki User

11y ago

The simple answer is that destructors do not accept parameters. A more pertinent question would be why do you want to pass parameters to destructors? What purpose would it serve?

Destructors exist purely to release the class instance members prior to releasing the object itself. This is important if the instance members allocate memory dynamically -- if the memory is not released during destruction, destroying the object would create a memory leak. Since the class has intimate knowledge of its own member variables, it is perfectly capable of releasing those members without the need for additional parameters. If you should happen to encounter an instance where a parameter would be useful in a destructor then perhaps you should consider redesigning your class as there's clearly a design flaw somewhere.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you cannot pass arguments to destructor in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you pass command line arguments using turbo in c compiler?

In the Options menu the Arguments command.


Elements of assembly language programming What is A simple assembly scheme pass structure of assembler design of two pass assemblers a single pass assemblers what is macros?

what are the elements of assembly language programming?


How many arguments pass in function?

zero or more it can be fixed or variable (printf is an example)


How do you pass a class in programming cplusplus?

A class is a type. You cannot pass a type in C++, you can only pass an object of the type, either by value or by reference. The only way to physically pass a type is to pass a void pointer (void*), then use expensive runtime type information to determine the runtime type of the object being referred to. However, it's much more efficient (and easier) to simply pass a base class that provides the generic (virtual) interface required by your function.


What are the different types of function in c plus plus programming?

There are five types of functions and they are:Functions with no arguments and no return values.Functions with arguments and no return values.Functions with arguments and return values.Functions that return multiple values.Functions with no arguments and return values.Functions with no arguments and no return value.A C function without any arguments means you cannot pass data (values like int, char etc) to the called function. Similarly, function with no return type does not pass back data to the calling function. It is one of the simplest types of function in C. This type of function which does not return any value cannot be used in an expression it can be used only as independent statement.Functions with arguments and no return value.A C function with arguments can perform much better than previous function type. This type of function can accept data from calling function. In other words, you send data to the called function from calling function but you cannot send result data back to the calling function. Rather, it displays the result on the terminal. But we can control the output of function by providing various values as arguments. Functions with arguments and return value.This type of function can send arguments (data) from the calling function to the called function and wait for the result to be returned back from the called function back to the calling function. And this type of function is mostly used in programming world because it can do two way communications; it can accept data as arguments as well as can send back data as return value. The data returned by the function can be used later in our program for further calculations. Functions with no arguments but returns value.We may need a function which does not take any argument but only returns values to the calling function then this type of function is useful. The best example of this type of function is "getchar()" library function which is declared in the header file "stdio.h". We can declare a similar library function of own. Functions that return multiple values.So far, we have learned and seen that in a function, return statement was able to return only single value. That is because; a return statement can return only one value. But if we want to send back more than one value then how we could do this? We have used arguments to send values to the called function, in the same way we can also use arguments to send back information to the calling function. The arguments that are used to send back data are called Output Parameters.It is a bit difficult for novice because this type of function uses pointer

Related questions

What is a sentence for formal?

You do not pass the formal arguments to the function like that. (in context with programming)You need to write a formal letter.


How do you pass the parameter in applet?

If you have the function main()... You can use its arguments to pass information.


How do you pass command line arguments using turbo in c compiler?

In the Options menu the Arguments command.


Elements of assembly language programming What is A simple assembly scheme pass structure of assembler design of two pass assemblers a single pass assemblers what is macros?

what are the elements of assembly language programming?


How will you pass arguments to a function in c plus plus?

If you have this function: int add(int x, int y) { return x + y; } you would pass the arguments when calling the function in the () like this: add(4, 7); 4 & 7 would be the arguments.


What is the least number of arguments you can pass to a Sub procedure?

anal sex


How can you pass run-time arguments in java?

Once you have compiled your Java source files: javac MyClass.java You can run the resulting class file and pass arguments: java MyClass arg0 arg1 arg2


How many arguments pass in function?

zero or more it can be fixed or variable (printf is an example)


What cannot pass through an opaque material?

Light cannot pass through an opaque material.


Why you pass arguments to function in c plus plus?

You pass arguments to functions because that is how you tell the function what you want it to do. If you had, for instance, a function that calculated the square root of something, you would pass that something as an argument, such as a = sqrt (b). In this case sqrt is the function name, b is passed as its argument, and the return value is assigned to a.


Can you pass argument to procedures?

Yes. Procedures are otherwise known as functions, and functions can accept arguments.


How do you pass a class in programming cplusplus?

A class is a type. You cannot pass a type in C++, you can only pass an object of the type, either by value or by reference. The only way to physically pass a type is to pass a void pointer (void*), then use expensive runtime type information to determine the runtime type of the object being referred to. However, it's much more efficient (and easier) to simply pass a base class that provides the generic (virtual) interface required by your function.