Lesson 16 of 24

Constructors, Destructors

10 min 30 XP

Object ഉണ്ടാകുമ്പോൾ constructor പ്രവർത്തിക്കുന്നു; നശിക്കുമ്പോൾ destructor (~ClassName) പ്രവർത്തിക്കുന്നു. Fields സജ്ജമാക്കാൻ ഏറ്റവും നല്ല വഴി initializer list (: name(n)) ആണ്. static member എല്ലാ objects-നും പൊതുവാണ്.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Block അവസാനിക്കുമ്പോൾ b-യുടെ destructor സ്വയം പ്രവർത്തിക്കുന്നു. ഇതാണ് RAII, resources-നെ object-ന്റെ ആയുസ്സുമായി ബന്ധിപ്പിക്കൽ, C++-ലെ ഏറ്റവും പ്രധാനപ്പെട്ട ആശയം.

Challenge

+30 XP

Constructor Time(int h, int m, int s), സമയം കൂട്ടുന്ന add(int seconds) (24 മണിക്കൂറിൽ ചുറ്റിവരും), "HH:MM:SS" രണ്ടക്കം വീതം print ചെയ്യുന്ന print() എന്നിവയുള്ള class Time എഴുതൂ. main()-ൽ h m s-ഉം കൂട്ടേണ്ട seconds-ഉം വായിച്ച് print ചെയ്യൂ. Input: 23 59 30 45 Output: 00:00:15

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.