继承的问题,怎么会变成递归了?
#include<iostream.h>class A1{ // 定义基类A1
int a1;
public:
A1(int i){a1=i;cout<<"constructor A1."<<a1<<endl;}
void print( ){cout<<a1<<endl;}
};
class A2{ // 定义基类A2
int a2;
public:
A2(int i){a2=i;cout<<"constructor A2."<<a2<<endl;}
void print(){cout<<a2<<endl;}
};
class A3{ // 定义A3
int a3;
public:
A3(int i){a3=i;cout<<"constructor A3."<<a3<<endl;}
int geta3( ){return a3;}
};
class B:public A2 , public A1{// 定义派生类 B,基类为A1和A2
int b;
A3 obj_a3; //对象成员
public:
B(int i,int j,int k,int l):A1(i),A2(j), obj_a3 (k)//派生类构造函数
{ b=l;
cout<<"constructor B."<<b<<endl;
}
void print()
{ static int c=1;
c++;
cout<<c<<endl;
print();
cout<<obj_a3. geta3()<<","<<b<<endl;
}
};
void main( )
{ B bb(1,2,3,4);
bb.print();//问题:为什么这里居然可以调用这个函数,调用次序有是怎么样的呢?请高手们指点指点迷津呢!!
}