Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. /*A destructor works opposite to constructor; it destructs the objects of classes.
  2. It can be defined only once in a class. Like constructors, it is invoked automatically.
  3.  
  4. Note: C++ destructor cannot have parameters. Moreover, modifiers can't be applied on destructors.
  5. */
  6. #include <iostream>
  7. using namespace std;
  8. class CodeToHelp
  9. {
  10. public:
  11. CodeToHelp()
  12. {
  13. cout<<"DEFAULT CONSTRUCTORE IS INVOKED\n";
  14. }
  15. ~CodeToHelp()
  16. {
  17. cout<<"Destructor is invoked\n";
  18. }
  19. }; //NOTE:- dont't forget to put semicolon at the closing bracket of CLASS
  20.  
  21. int main() {
  22. CodeToHelp h1; //object are created of class CodeToHelp
  23. CodeToHelp h2; //AGAIN NOTE:- constructor will invoke First and AT THE END DESTRUCTOR IS INVOKED;
  24. // as the destructor destructs the objects of classes.
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement