天府星入命人特征:还有两道C++改错题 谢谢那位高手咯~~~~

来源:百度文库 编辑:神马品牌网 时间:2024/05/11 03:31:41
7.找出下面程序中的错误,并改正
#include <iostream.h>
class A{
public: void fun( ){cout<<"A.fun"<<endl;}
};
class B{
public: void fun( ){cout<<"B.fun"<<endl;}
void gun( ){cout<<"B.gun"<<endl;}
};
class C:public A,public B{
private:int b;
public:void gun( ){cout<<"C.gun"<<endl;}
void hun( ){fun( );}
};
8.找出下面程序中的错误,并改正
class one{
private:
int a;
public:
void func(two&);
};
class two{
private:
int b;
friend void one::func(two&);
};
void one::func(two& r)
{
a=r.b;
}

7。
#include <iostream.h>
class A{
public: void fun( ){cout<<"A.fun"<<endl;}
};
class B{
public: void fun( ){cout<<"B.fun"<<endl;}
void gun( ){cout<<"B.gun"<<endl;}
};
class C:public A,public B{
private:int b;
public:void gun( ){cout<<"C.gun"<<endl;}
void hun( ){A::fun( );} //or B::fun()不然会歧义
};

8。a=r.b;//b是two里的私有成员,不能访问!不知道怎么改好!定义b为public?????