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.