哪位VC6.0的高手帮帮我?《〈这个程序错在哪里?怎么改正

来源:百度知道 编辑:UC知道 时间:2024/06/04 21:32:34
#include <iostream.h>
class animal
{
public:
void eat()
{
cout<<"animal eat"<<endl;
}
protected:
void sleep()

{
cout<<"animal sleep"<<endl;
}
void breathe()
{
cout<<"animal breathe"<<endl;
}
};
class fish : public animal
{
void test()
{
sleep();
breathe();
}

};
void main()
{
animal an;
an.eat();
fish fi;
fi.sleep();

}

问题很明显呀
animal类的成员函数sleep()是protected

fish类public继承animal,但是sleep()还是protected

fish fi;
fi.sleep();//不能访问,肯定出错

#include <iostream.h>
class animal
{
public:
void eat()
{
cout<<"animal eat"<<endl;
}

void sleep()

{
cout<<"animal sleep"<<endl;
}
void breathe()
{
cout<<"animal breathe"<<endl;
}
};
class fish : public animal
{
void test()
{
sleep();
breathe();
}

};
void main()
{
animal an;
an.eat();
fish fi;
fi.sleep();

}

是不是继承出错了,Public是代表继承公共部分吧 ?