What are the constructors and destructors in C++?? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 6

What are the constructors and destructors in C++??

ūüŹĶūüĆľūüíźūüĆłūüíģūüŹĶūüíźūüĆłūüĆľ

15th Apr 2019, 7:52 AM
Nithya Yamasinghe
Nithya Yamasinghe - avatar
3 Réponses
+ 7
Constructors allocate memory for objects and initialize them. Destructors free the memory and other resources.
15th Apr 2019, 11:15 PM
Sonic
Sonic - avatar
+ 4
Constructors do not allocate memory for objects (that's done with 'new'). They are used to initialize an object (instance of a class) with an valid state.
16th Apr 2019, 12:04 PM
Daniel Adam
Daniel Adam - avatar