以下面的例子举例:
#include<iostream>
using namespace std;
class B {
public:
B() { cout << "B0::B()" << endl; }
B(int a) { cout << "B1::B()" <<" "<< "a=" << a << endl; }
~B() { cout << "~B()" << endl; }
};
class D :public B {
public:
D() { cout << "D0::D()" << endl; }
D(int a) { cout << "D1::D()" <<" "<< "a=" << a << endl; }
~D() { cout << "~D()" << endl; }
};
下面是各种main()函数的情况
1.
int main() {
B b;
return 0;
}
int main() {
D d;
return 0;
}
int main() {
B b = B(); // //只有一个B的对象,调用的是B()构造函数
B b1 = B(1); //只有