iterator for vector of pointers to generic type won't compile
Bug #311663 reported by
Mike Gashler
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-4.2 (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
This function iterates over a vector to find an element. It won't compile with g++ 4.2.4
#include <vector>
template<typename T>
size_t index_of(
{
for(std:
if(p == *it)
return (it - v.begin());
return -1;
}
The error is:
error: expected `;' before ‘it’
Visual C++ 2005 can compile this code. I know that doesn't always mean much, but in this case I think they are correct. If I am mistaken such that this code really should not compile, the issue is definitely not a missing semicolon before 'it', so at least the error message could be improved a bit.
To post a comment you must log in.
My mistake. Sorry. The solution is to change this line T*>::iterator it = v.begin(); it != v.end(); it++) T*>::iterator it = v.begin(); it != v.end(); it++)
for(vector<
to
for(typename vector<