我有一个cpp
程序,它以一些双精度值作为输入并计算这些值的总和。数组的长度不稳定。它随着输入的数量而变化。所以我选择for each
在函数内部使用循环。以下是我的代码。
double getTotal (double arr[]){
double total = 0;
for (double x : arr){
total += x;
}
return total;
}
上面的代码给了我以下错误
main.cpp: In member function ‘double My1DArray::getTotal(double*)’:
main.cpp:39:28: error: ‘begin’ was not declared in this scope
for (double x : arr){
^
我尝试使用arr.size()
它给了我一堆错误。
什么原因导致问题?