以下を考えると:
#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;
劇的な影響はありますか?