好的,所以这看起来很简单,但是当它不起作用时它会爆炸我的大脑。这是一个非常简单的几个类。(在 VC++ 中)
class Food
{
protected:
char maxAmountCarried;
};
class Fruit:Food
{
protected:
Fruit()
{
maxAmountCarried = 8; // Works fine
}
};
class Watermelon:Fruit
{
protected:
Watermelon()
{
maxAmountCarried = 1; //Food::maxAmountCarried" (declared at line 208) is inaccessible
}
};
所以基本上,我希望水果的最大承载能力默认为 8。西瓜要大得多,所以容量改为 1。但是,不幸的是我无法访问该属性。
如果有人能告诉我解决这个问题的方法,那将是非常有帮助的。
提前致谢 :)