Hi,
I have run the following program and got the following input.
Out : this is constructor
When I have removed below comment ( //cout<<this) into destructor and become
into infinite loop.
Could not figure out this issue. does cout impact destrcutor.
#include<iostream>
using namespace std;
class sample
{
public:
sample()
{
cout<<" this is constructor"<<endl;
}
~sample()
{
//cout<<" this";
delete this;
cout<<"des";
}
};
int main()
{
sample *s = new sample;
delete s;
return 0;
}
Last edited on
I believe delete this;
will call the destructor. Therefore your destructor is recursive without an exit condition. You don't need to call that line.