c++高手到哪里去了,帮我分析结果,先谢谢了!

来源:百度知道 编辑:UC知道 时间:2024/06/05 15:54:57
c++高手请进:帮我看一下输出结果?解释一下更好!
悬赏分:0 - 离问题结束还有 13 天 16 小时
#include"iostream.h"
class A
{
public:
A(int a,int b)
{
i=a;j=b;
}
void move(int x,int y)
{
i+=x;
j+=y;
}
void show()
{
cout<<"("<<i<<",j"<<")"<<endl;
}
private:
int i,j;
};
class B:private A
{
public:
B(int a,int b,int c,int d):A(a,b){x=c;y=d;}
void show() {cout<<x<<","<<y<<endl;}
void f1(){move(3,6);}
void f2(){A::show();}
private:
int x,y;
};
void main()
{
A q(1,2);
q.show();
B r(5,6,7,8);
r.f1();
r.show();
r.f2();
}

class B:private A
{
public:
B(int a,int b,int c,int d):A(a,b){x=c;y=d;}
void show() {cout<<x<<","<<y<<endl;}
void f1(){move(3,6);} //调用的是A的move函数;
void f2(){A::show();}
private:
int x,y;
};

void main()
{
A q(1,2);
q.show(); //这些就不说了
B r(5,6,7,8); //用(5,6)实例化了一个A类型的对象,并继承;结合B的构造函数看看
r.f1(); //这里会对刚才实例化的A对象进行操作也就是5+3,6+6;
r.show();
r.f2(); //这两个都是输出对应的数据,看看具体的函数就可以了
}