#include <iostream.h>
class A {
public:
A(int n):num(n) { Out( ); }
A(const A& rhs):num(rhs.num)
{Out( );}
void Out( ) {cout<<num<<endl; }
private:
int num;
};
class B:public A {
public:
B(A& a) :obj(a),A(1) { }
void Out( ) { obj.Out( ); }
private:
A obj;
};
int main( )
{
A a(8);
B b1(a);
B b2(b1);
b2.Out();
return 0;
}
输出为8 1 8 1 8 8
这段程序很适合C++新手去练习理解