Created
April 17, 2020 10:30
-
-
Save rajan9519/cde25dd904562eb06866b5a97319cfcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<bits/stdc++.h> | |
| using namespace std; | |
| class student | |
| { | |
| private: | |
| string name; | |
| int rollNumeber; | |
| public: | |
| student(); // custom default Constructor | |
| ~student(); // custom destructor | |
| }; | |
| student::student() | |
| { | |
| name = "No Name"; | |
| rollNumeber = 0; | |
| } | |
| student::~student() | |
| { | |
| cout<<"destructor is called\n"; | |
| // your code to delete to free this memory segment | |
| } | |
| void test() | |
| { | |
| student st1,st2; // creating student object on stack | |
| } | |
| int main() | |
| { | |
| student *s = new student; // creating student object on heap | |
| test(); // destructor called on stack object when function returns | |
| delete s; // destructor called for heap object | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment