//结果:
//(1,2)
//5,6
//(6,9)
#include <iostream.h>
class A
{
public:
A(int i,int j)
{
a=i;
b=j;
}
void Offset(int x,int y)
{
a+=x;
b+=y;
}
void Display()
{
cout<<'('<<a<<','<<b<<')'<<endl;
}
private:
int a,b;
};
class B:private A
{
public:
B(int i,int j,int k,int l):A(i,j){x=k;y=l;}
void Display()
{
cout<<x<<','<<y<<endl;
}
void Move()
{
Offset(3,5);
}
void Show()
{
A::Display();
}
private:
int x,y;
};
void main()
{
A e(1,2);//a=1 b=2
e.Display();// (1,2)
B d(3,4,5,6);// a=3 b=4 x=5 y=6
d.Move(); //继承基类 并传参给Offset函数 也就是a+=3;b+=5
d.Display(); //5,6
d.Show(); //6,9 注: 6=3+3 9=4+5
}