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

67 lines
745 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 设已经有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()
*/