C++: Why constructor cannot be virtual but destructor can? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++: Why constructor cannot be virtual but destructor can?

constructor destructor in c++

1st Oct 2018, 4:26 PM
Sumit
1 Answer
+ 2
Because, constructor is not "invoked". It is called only once when an object is declared. So, a constructor cannot be made virtual in C++. Virtual destructors are important to prevent memory leaks, and monitor the system
1st Oct 2018, 4:57 PM
Shimmu