【发布时间】:2011-02-19 08:03:21
【问题描述】:
如果可能的话,我需要一些帮助来解决这个问题。我对此还是很陌生,所以请原谅我。我有一个对象数组,我想要一个方法来为我操作。我不确定如何最好地用文字表达,所以我将举一个例子。
#include <iostream>
using namespace std;
class fruit
{
private:
int amount;
public:
void eat();
};
void fruit::eat()
{
//manipulate the amount for apples at both indexes here
}
int main()
{
fruit apples[2];
fruit pie;
pie.eat();
return 0;
}
我想使用eat() 函数更改apples 数组中两个索引处的数量。我将如何去做这件事。如果这看起来很愚蠢,我很抱歉。
【问题讨论】:
-
首先,如果你完成了你的家庭作业,毫无疑问是愚蠢的。其次我还是不清楚你想要什么?