鉴于以下情况:
#include <iostream>
using namespace std;
class A
{
public:
void func() {delete this;}
A() : x(5) {cout << "ctor A" << endl;}
~A() {cout << "dtor A" << endl;}
int x;
};
int main() {
A a;
cout << "The X value: " << a.x << endl;
a.func(); // calling 'delete this' ->going to the dtor #1
cout << "The X value: " << a.x << endl;
return 0;
}
输出是:
ctor A
The X value: 5
dtor A
The X value: 5
dtor A
有没有delete this;
什么严重的影响?