Lesson 16 of 24
Constructors மற்றும் DestructorsConstructors and Destructors
10 min 30 XP
Constructor object உருவாகும்போது இயங்கும்; destructor (~ClassName) object அழியும்போது இயங்கும். Initializer list (: name(n)) fields-ஐ அமைக்கும் சிறந்த வழி. static member எல்லா objects-க்கும் பொதுவானது.
A constructor runs when an object is created; the destructor (~ClassName) runs when it is destroyed. An initializer list (: name(n)) is the best way to set fields. A static member is shared by all objects.
Example: edit me and press Run
Press Run to see the result here.Block முடிந்தவுடன் b-ன் destructor தானாக இயங்குகிறது. இதுவே RAII: resources-ஐ object-ன் வாழ்நாளுடன் இணைப்பது. C++-ன் மிக முக்கியமான கொள்கை.
b's destructor runs automatically when the block ends. This is RAII, tying resources to an object's lifetime, and it is the most important idea in C++.