class Fruit{
};
class Banana: public Fruit
{
public:
bool isRipe(){
if (mColor == ‘y’){
return true;
}
else{
return false;
}
}
};
main(){
Banana banana;
banana.setColor(‘y’);
if(banana.isRipe()){
cout << “banana is ready to eat” << endl;
}
else{
cout << “banana is not ready to eat” << endl;
}
}
这是需要编译的代码,但抛出下面的错误: -错误而执行的C++代码
$\fruit.cpp||In member function 'bool Banana::isRipe()':|
$\fruit.cpp|17|error: 'y' was not declared in this scope|
$\fruit.cpp||In function 'int main()':|
$\fruit.cpp|28|error: 'class Banana' has no member named 'setColor'|
$\fruit.cpp|28|error: 'y' was not declared in this scope|
$\fruit.cpp|30|error: 'cout' was not declared in this scope|
$\fruit.cpp|30|error: expected ';' before 'is'|
$\fruit.cpp|33|error: 'cout' was not declared in this scope|
$ \ fruit.cpp | 33 |错误:预期 ';'在'is'之前| || ===构建失败:32个错误,0个警告(0分钟,0秒)=== |
我想使用给定派生类的水果的基类,但没有得到它的权利。任何帮助表示赞赏。
请提供实际的代码以及错误。如果我们没有任何一个,我们如何猜测出现了什么问题? – Quentin
_不正确_继续下去并不是很有用。预期产出是多少?目前的产出是多少?你似乎也错过了'setColor'的声明/定义,尽管它大概在'Fruit'类中。 – Tas
为什么你想从一个空白的课程派生。格式化让我想哭:'( –