When is it advised to have user defined destructor?

Huỳnh Hiền

New member
When is it advised to have user defined destructor?
A. When class contains some pointer to memory allocated in class
B. When a class contains static variables
C. When a class contains static functions
D. When a class is inheriting another class only
 
Answer: a
Explanation: This is always advised to have user defined destructor when pointers are involved in class. This is usually done to ensure that the memory, that was allocated dynamically, gets free after use and doesn’t cause memory leak.
 

Tìm kiếm

Back
Top