以下のコードは安全に実行されているのだろうか。
#include <iostream>
using namespace std;
class A
{
public:
A() {
cout << "Constructor" << endl;
}
~A() {
cout << "Destructor" << endl;
}
void deleteMe() {
delete this;
cout << "I was deleted" << endl;
}
};
int main()
{
A *a = new A();
a->deleteMe();
cout << "Exit ...";
return 0;
}
出力は次のとおりです。
Constructor
Destructor
I was deleted
Exit ...
プログラムは正常に終了しますが、ここにメモリアクセスの暴力がありますか?