Duplicate. See this.
Can someone tell me why this does not compile under GCC? Both MSVC6, and VS2008 will compile it, with no warnings, even.
The code…
#include <iostream> #include <vector> #include <ctime> #include <cstdlib> using namespace std; template <typename T> T range(vector<T> &v) { vector<T>::iterator i = v.begin();
Throws an error on the last line, expected ; before i.
Do I need to typedef?
Most of the compiling I do is with MSVC6, or VS2008. I don’t do a whole lot with GCC, so I’m a little in the dark.
The compiler does not know enough to parse vector::iterator as a type at that point. Use the typename keyword to give it a hint: