What is the problem of this program when I execute , I want class be destructed, but end of the program I see the error box after cout fetch.
What is the problem?
#include <iostream>
using namespace std;
class user {
public:int internal;
public:user(int point) {
internal = point;
};
~user () {
cout << "Fetch";
}
};
void main() {
user gil(5);
user * p;
p=&gil;
delete p;
getchar();
}
Try:
To avoid using
new/deleteand have the variable destructed when it falls out of scope: