209k views
1 vote
What happens when you define a class that used dynamic memory allocation and define a destructor but no copy constructor?

a. If an object of the class is plugged in for a call-by-value parameter, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
b. When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error. c. It is possible to modify the values in the argument in the function.
d. All of the above e. None of the above
All of the above.
If an object of the class is plugged in for a call-by-value parameter, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error.
It is possible to modify the values in the argument of the function.
If obj1 and obj2 are both

User Gafar
by
8.7k points

1 Answer

3 votes

Final answer:

When you define a class with dynamic memory allocation and a destructor but no copy constructor, several consequences occur.

Step-by-step explanation:

When you define a class that uses dynamic memory allocation and define a destructor but no copy constructor, several things happen:

  1. If an object of the class is passed as a call-by-value parameter in a function, when the function ends, the parameter's dynamic memory is returned to the freestore at the end of the function execution.
  2. When an object that was used as an argument for a call-by-value parameter goes out of scope, it will cause a run-time error because the destructor will be called to deallocate the dynamic memory twice.
  3. It is possible to modify the values in the argument of the function, since the object is passed by value.
User Vijesh
by
7.8k points