qfedu-cpp-level/day4/homework/h2.cpp

67 lines
745 B
C++
Raw Permalink Normal View History

2023-07-27 21:04:06 +08:00
// 设已经有A,B,C,D 4个类的定义程序中A,B,C,D析构函数调用顺序为
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
class A
{
public:
A() { cout << "A()" << endl; }
~A()
{
cout << "~A()" << endl;
}
};
class B
{
public:
B() { cout << "B()" << endl; }
~B()
{
cout << "~B()" << endl;
}
};
class C
{
public:
C() { cout << "C()" << endl; }
~C()
{
cout << "~C()" << endl;
}
};
class D
{
public:
D() { cout << "D()" << endl; }
~D()
{
cout << "~D()" << endl;
}
};
C c;
int main()
{
A *pa = new A();
B b;
static D d;
delete pa;
}
/*
C()
A()
B()
D()
~A()
~B()
~D()
~C()
*/