C++一个关于继承的练习小程序的问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 05:03:19
程序如下
#include <iostream>
using namespace std;
class Father
{
/*private:全部私有,不允许任何类访问*/protected/*允许派生类(子类)访问父类私有数据*/:
int FatherTall,FatherWeight;
public:
void SetFatherTall(int FatherSTall){FatherTall=FatherSTall;}
void SetFatherWeight(int FatherSWeight){FatherWeight=FatherSWeight;}
//void PrintFatherTallWeight(){cout<<"Tall="<<FatherTall<<'\t'<<"Weight="<<FatherWeight<<endl;}
};
class Son:public Father
{
private:
int SonWidth,SonLong;
public:
void SetSonWidth(int SonSWidth){SonWidth=SonSWidth;}
void SetSonLong(int SonSLong){SonLong=SonSLong;}
//void PrintSonWidthLong(){cout<<"Width="<<SonWidth<<'\t'<<"Long="<<SonLong<<endl;}
void SetAll(int FatherSTall,FatherSWeight,SonSWidth,SonSLong)
{
FatherTall=FatherSTall;
Father

void SetAll(int FatherSTall,FatherSWeight,SonSWidth,SonSLong)每个参数前都要类型
所以都把int加上

你把那个protected写的那么隐蔽,我还以为int FatherTall,FatherWeight是私有的呢

同学你好
把void SetAll(int FatherSTall, FatherSWeight, SonSWidth,SonSLong)改成void SetAll(int FatherSTall,int FatherSWeight,int SonSWidth,int SonSLong)就行了