注册 登录
编程论坛 C++教室

[求助]vc++中不能继承

zxh321 发布于 2007-09-22 22:03, 489 次点击

#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 main()
{
Animal an;
an.eat();
Fish fh;
fh.sleep;


}

为什么运行的结果只有animal eat,Fish没办法继承

5 回复
#2
valentineyzq2007-09-22 22:49

最后一句改成fh.Animal::sleep();

#3
etherli2007-09-22 23:28

void main()
{
Animal an;
an.eat();
Fish fh;
fh.sleep(); //你的程序少了括号,注意sleep()是个函数
}

呵呵 有时跟我一样粗心
#4
风致2007-09-23 00:51
呵呵,是啊,编程确实要细心,我也很粗心!
#5
valentineyzq2007-09-23 09:33


原来是括号的原因啊。

#6
zxh3212007-09-27 12:39
原来是这样
1