谢谢大神对小友的一路指点!不过小友最近有遇到问题了!
#include <iostream>class A
{
public:
A() { cout << "A Constructor1" <<endl;
A(int i) { x1=i;cout <<"A Constructor2" <<endl;
void dispa() { cout << "x1=" << x1 <<endl;};
private:
int x1;
};
class B :public A
{
public:
B() {cout << "b Constructor1" <<endl;}
B(int i): A(i+10) { x2=i;cout << "B Constructor2" <<endl;}
void dispb()
{
dispb();
cout << "x2=" <<x2<<endl;
}
private:
int x2;
};
void main()
{
B b(2);
b.dispb();
}
最近看到派生构造函数了,但是这个程序怎么看也看不懂!还请大神给小友分析一下程序是咋运行的???