// function to modify array object
void fill(std:;array<double, Seasons> & pa);
// function that uses array object without modifying it
void show(const std:;array<double, Seasons> & da);
注意,show()应使用const,以禁止修改对象。
接下来,在main()中,将fill()调用改为下面这样:
fill(expenses);
函数show()的调用不需要修改。
接下来,新的fill()应类似于下面这样:
void fill(std:;array<double, Seasons> & pa) // changed
{
using namespace std;
for (int i = 0; i < Seasons; i++)
{
cout << "Enter " << Snames[i] << " expenses: ";
cin >> pa[i]; // changed
}
}