Q:

When do we need to write a user-defined destructor?

0

When do we need to write a user-defined destructor?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

If we do not write our own destructor in class, the compiler creates a default destructor for us. The default destructor works fine unless we have dynamically allocated memory or pointer in class. When a class contains a pointer to memory allocated in class, we should write a destructor to release memory before the class instance is destroyed. This must be done to avoid the memory leak.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions For Experienced

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Why a class has only one destructor in c++?... >>
<< What is the conversion operator in C++?...