2010-08-09 5 views
3

가능한 중복 :
g++ “is not a type” error벡터 <T> :: iterator - invalid?

것은 다음은 컴파일되지 않습니다 :

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

을 비주얼 스튜디오에, 나는 다음과 같은 오류 얻을 :

>(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 
+1

(http://stackoverflow.com/questions/1301380/g-is-not-a-type-error) , 더 있지만 나는 그들을 찾을 수 없습니다. : S – GManNickG

답변

13

std::vector<T>::iterator은 템플릿 매개 변수에 에 종속 인 인 형식, 즉 T입니다. 따라서, 당신은 그것으로 typename 접두사한다 :이 [중복]을 찾을 수

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

Here's an explanation.

+0

+1 나보다 빠릅니다. –

+0

@Fred : 허용 된 답변에 대해 빠르게 촬영하고 있습니다. : P – GManNickG

+0

하하, 나는 내일 당신의 대답을 받아 들일 것입니다 :) (그래서 당신은 +15를 얻을 수 있습니다) – Jacob