Что не так с моим использованием поиска стандартной библиотеки C ++?

Я пытаюсь использовать алгоритм find стандартной библиотеки C ++ следующим образом:

  template<class T>
  const unsigned int AdjacencyList<T>::_index_for_node(
      const std::vector<T>& list, const T& node
  ) throw(NoSuchNodeException)
  {
    std::vector<T>::iterator iter = std::find(list.begin(), list.end(), node);
  }

Когда я пытаюсь скомпилировать, я получаю следующие ошибки:

In file included from ../AdjacencyList.cpp:8:
../AdjacencyList.h: In member function ‘const unsigned int Graph::AdjacencyList<T>::_index_for_node(const std::vector<T, std::allocator<_Tp1> >&, const T&)’:
../AdjacencyList.h:99: error: expected ‘;’ before ‘iter’
../AdjacencyList.h:100: error: ‘iter’ was not declared in this scope
In file included from ../AdjacencyListTest.cpp:9:
../AdjacencyList.h: In member function ‘const unsigned int Graph::AdjacencyList<T>::_index_for_node(const std::vector<T, std::allocator<_Tp1> >&, const T&)’:
../AdjacencyList.h:99: error: expected ‘;’ before ‘iter’
../AdjacencyList.h:100: error: ‘iter’ was not declared in this scope
../AdjacencyList.h: In member function ‘const unsigned int Graph::AdjacencyList<T>::_index_for_node(const std::vector<T, std::allocator<_Tp1> >&, const T&) [with T = int]’:
../AdjacencyList.h:91:   instantiated from ‘const std::vector<T, std::allocator<_Tp1> > Graph::AdjacencyList<T>::neighbours(const T&) [with T = int]’
../AdjacencyListTest.cpp:18:   instantiated from here
../AdjacencyList.h:99: error: dependent-name ‘std::vector::iterator’ is parsed as a non-type, but instantiation yields a type
../AdjacencyList.h:99: note: say ‘typename std::vector::iterator’ if a type is meant

I кажется, что «зависимое имя 'std :: vector :: iterator' анализируется как не тип, но создание экземпляра дает тип», бит содержит ключ к пониманию того, что я делаю неправильно, но мой мозг не может извлечь значение.

Обновление: Мне нужно было добавить typename в соответствии с принятым ответом, а также использовать const_iterator , поэтому проблемная строка кода стала:

    typename std::vector<T>::const_iterator iter = std::find(list.begin(), list.end(), node);
15
задан Deduplicator 30 August 2015 в 17:23
поделиться