Skip to content

Instantly share code, notes, and snippets.

@rajan9519
Created April 17, 2020 10:30
Show Gist options
  • Select an option

  • Save rajan9519/cde25dd904562eb06866b5a97319cfcd to your computer and use it in GitHub Desktop.

Select an option

Save rajan9519/cde25dd904562eb06866b5a97319cfcd to your computer and use it in GitHub Desktop.
#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