Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*A destructor works opposite to constructor; it destructs the objects of classes.
- It can be defined only once in a class. Like constructors, it is invoked automatically.
- Note: C++ destructor cannot have parameters. Moreover, modifiers can't be applied on destructors.
- */
- #include <iostream>
- using namespace std;
- class CodeToHelp
- {
- public:
- CodeToHelp()
- {
- cout<<"DEFAULT CONSTRUCTORE IS INVOKED\n";
- }
- ~CodeToHelp()
- {
- cout<<"Destructor is invoked\n";
- }
- }; //NOTE:- dont't forget to put semicolon at the closing bracket of CLASS
- int main() {
- CodeToHelp h1; //object are created of class CodeToHelp
- CodeToHelp h2; //AGAIN NOTE:- constructor will invoke First and AT THE END DESTRUCTOR IS INVOKED;
- // as the destructor destructs the objects of classes.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement