I have a function that returns the sum of elements in an std::vector, but I'm having issues with iterators. (line numbers added for clarity)
I'm compiling this on OpenSuse linux 10.3, kernel version 2.6.22.5-31-default, using GCC 4.2.1, and I get the following errors:Code:4 : template<class T> T sum(std::vector<T>& v) 5 : { 6 : T tmp = 0; 7 : for (std::vector<T>::iterator it = v.begin(); it != v.end(); it++) 8 : { 9 : tmp += *it; 10: } 11: return tmp; 12: }
xxx.cpp:7: error: expected ';' before 'it'
xxx.cpp:7: error: 'it' was not declared in this scope