继承
复合
代码验证
#include<iostream>
using namespace std;
class A {
public:
A() { cout << "调用A构造" <<endl; }
~A() { cout << "调用A析构" <<endl; }
};
class B :public A {
public:
B() { cout << "调用B构造" <<endl; }
~B() { cout << "调用B析构"<<endl; }
};
class C {
private:
A a;
public:
C() { cout << "调用C构造" << endl; }
~C() { cout << "调用C析构" << endl; }
};
int main() {
B b;
C c;
system("pause");
}