I have declared a simple class with constructor and destructor. But, when I delete the object, it gives runtime error
and executes no further output.
class Student {
public:
string name;
Student(string name) {
this->name=name;
}
~Student() {
this->name="";
}
};
int main() {
Student* s = new Student("a");
cout<<s->name<<endl;
delete s; /// Problem In This Line
cout<<"Name Here -> "<<s->name<<endl;
return 0;
}
What is my problem here?? How should I delete or call the destructor??