C++: Why constructor cannot be virtual but destructor can? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

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

constructor destructor in c++

1st Oct 2018, 4:26 PM
Sumit
1 Réponse
+ 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