C++ | Operator Overloading | Question 10
Predict the output?
new called Constructor called delete called Destructor called
new called Constructor called Destructor called delete called
Constructor called new called Destructor called delete called
Constructor called new called delete called Destructor called
Explanation: Consider the following statement
Test *ptr = new Test;
There are actually two things that happen in the above statement–memory allocation and object construction; the new keyword is responsible for both. One step in the process is to call operator new in order to allocate memory; the other step is to actually invoke the constructor. Operator new only allows us to change the memory allocation method, but does not do anything with the constructor calling method. Keyword new is responsible for calling the constructor, not operator new.
Quiz of this Question