Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Deconstructors are code that runs after objects get destroyed.
- Objects get destroyed when the program ends!
- Here is one example:
- #include <iostream>
- #include <stdlib.h> /* system, NULL, EXIT_FAILURE */
- using namespace std;
- class Room
- {
- public:
- Room()
- {
- cout << "I am the constructor!" << endl; //I run when an object gets created!
- }
- ~Room()
- {
- cout << "I am the deconstructor!" << endl; //I run when an object gets destroyed! //Also notice the ~ in the beginning!
- }
- };
- int main()
- {
- Room object; //Constructor
- cout << "Hello World!" << endl; //Text
- system("pause"); //Pause
- /*And finally here the deconstructor run!*/
- return 0;
- }
Add Comment
Please, Sign In to add comment