构造函数会自动调用基类的构造函数~~~
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif) Code #include <stdio.h> #include <iostream> using namespace std;
class A { public: A() {cout<<"A构造"<<endl;} A(int i) {cout<<"A构造:i"<<endl;} ~A() { cout<<"A析构"<<endl;} }; class B :public A { public: B() { cout<<"B构造"<<endl;} B(int i):A(i) { cout<<"B构造"<<endl;} ~B() { cout<<"B析构"<<endl;}
};
int main() {
B b;
getchar(); return 0; }
输出什么呢?
![](https://images.cnblogs.com/cnblogs_com/mikewolf2009/220360/r_1.JPG)
|