#include <iostream>
using namespace std;
class base;
base* b = nullptr;
class base {
public:
base* m_b = nullptr;
base() {
m_b = this;
b = this;
}
~base() {
cout << "base 被析构\n";
}
};
class child :public base{
public:
child() {}
~child() {
delete m_b;//子类弑父
cout << "child 被析构\n";
}
}
;
class child2 :public base {
public:
child2() {}
~child2() {
cout << "child 被析构\n";
}
};
int main()
{
//子类弑父
child* c = new child();
delete c;
//弑父之仇
child2* c2 = new child2();
delete b;
delete c2;
std::cout << "Hello World!\n";
}
以上两种情况都会造成