3

Possible Duplicate:
g++ “is not a type” error

The following does not compile:

1    template<typename T>
2    void foo(std::vector<T>::iterator & i)
3    {  
4    }

On Visual Studio, I get the following errors:

>(2) error C2065: 'i' : undeclared identifier
>(4) warning C4346: 'std::vector<_Tp>::iterator' : dependent name is not a type
     prefix with 'typename' to indicate a type
>(4) error C2182: 'foo' : illegal use of type 'void'
>(4) error C2998: 'int foo' : cannot be a template definition
Community
  • 1
  • 1
Jacob
  • 34,255
  • 14
  • 110
  • 165
  • 1
    Found this [duplicate](http://stackoverflow.com/questions/1301380/g-is-not-a-type-error), there are more but I cannot find them. :S – GManNickG Aug 09 '10 at 20:52

1 Answers1

14

std::vector<T>::iterator is a type that is dependent on a template parameter, namely T. Therefore, you should prefix with it typename:

template<typename T>
void foo(typename std::vector<T>::iterator & i)
{  
}

Here's an explanation.

GManNickG
  • 494,350
  • 52
  • 494
  • 543