【发布时间】:2014-01-25 17:17:42
【问题描述】:
我为我的学校项目编写了一个简短的程序来说明继承的原则,但我遇到了一个奇怪的问题。这是我的代码:(我省略了所有不是问题的代码)
class Car
{
protected:
double fuelLevel;
public:
void fuelUp(double);
};
void fuelUp(double fuel)
{
Car::fuelLevel += fuel;
}
这是构建日志:
||=== Build: Debug in wierdError (compiler: GNU GCC Compiler) ===|
||In function 'void fuelUp(double)':|
|4|error: 'double Car::fuelLevel' is protected|
|11|error: within this context|
|4|error: invalid use of non-static data member 'Car::fuelLevel'|
|11|error: from this location|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
我不知道这个错误意味着什么,我希望有人可以帮助我。
【问题讨论】:
-
+1 用于省略所有没有问题的代码。
-
你需要
void Car::fuelUp(double fuel)... -
好的,谢谢。我发誓我为这种错误阅读了大约十次代码。
-
已建议但不适用于这种情况:stackoverflow.com/questions/46943651/…
标签: c++ class static protected