2014-10-12 3 views
0

'반복자는 유형이 아닌'여기 내 코드입니다 : 나는 오류 'iterator is not a type'를 얻을 수C++ 오류 :

template <typename container_type> 
void transfer(container_type container, iterator begin, iterator end) { 
    for (; begin != end; begin++) 
     if (!element_in_container(container, *begin)) 
      container.insert(iterator, *begin); 
} 

가.

또는 container_type::iterator 앞에 추가하려고 시도했지만 도움이되지 않았습니다. 템플릿을 template <typename container_type<typename T> >으로 정의하고 이터레이터를 container_type<T>::iterator (운 없음)으로 정의 해 보았습니다. 뭐가 문제 야?

+4

'typename container_type :: iterator'는 어떻습니까? –

+1

실제로 iterator는 타입이 아닙니다. –

+0

가능한 복제본 : [어디서 왜 "템플릿"및 "typename"키워드를 넣어야합니까?] (http://stackoverflow.com/questions/610245/where-and-why-do-i-have- template-and-typename-keywords) –

답변

4

나는 다음과 같은

template <typename container_type> 
void transfer(container_type container, typename container_type::iterator begin, 
             typename container_type::iterator end) { 

컨테이너의 반복자의 요소를 삽입 한 후 유효하지 않을 수 있기 때문에 어떤 경우에 함수가 잘못된 것을 고려 의미 생각합니다.

1

I tried adding std:: or container_type:: before iterator, didn't help.

container_type::iterator는 유형 (typename container_type::iterator)로 치료 전에 그러므로 당신이 typename 키워드를 필요 종속 이름입니다. 자세한 내용은 here에 설명되어 있습니다.