#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
template <typename Iter>
double vectorSum(Iter begin, Iter end) {
double sum = 0.0;
while( begin != end )
sum += *begin++;
return sum;
}
int main() {
double temperature[] = { 10.5, 20.0, 8.5 };
cout << "array vectorSum = "
<< vectorSum(temperature,temperature+sizeof temperature/sizeof temperatu
re[0])
<< endl;
return 0;
}
/*
array vectorSum = 39
*/
|