我将要纠正一些关于C++/STL的代码。不幸的是,我对于C++并没有很多经验,也不了解STL。尽管如此,我已经完成了大部分工作,但是下面这个函数仍然让我头疼:
C++源码:
double MyClass::CalculateAvg(const std::list<double> &list)
{
double avg = 0;
std::list<int>::iterator it;
for(it = list->begin(); it != list->end(); it++) avg += *it;
avg /= list->size();
}
C++ 头文件:
static double CalculateAvg(const std::list<int> &list);
这段文字很可能是用于计算列表中的平均值,但其中存在许多错误。我尝试在网络上寻找解决方案,但没有找到任何有用的信息。如果有人能帮助我解决问题,我将不胜感激。
更新: 感谢您的快速回复。接受的答案解决了我所有的问题。