Using vector iterators with in a template class

c++, iterator, stl, templates

Solution

If `buffer` is a `std::vector< std::vector<T> >` then `buffer.begin()` is a `std::vector< std::vector<T> >::iterator` or `const_iterator`, so your `typedef` doesn't match.

Problem

I am attempting to create a vector iterator within a template class I am creating. The following is the trouble code. ``` void editor<T>::insert() { typedef typename std::vector<T>::const_iterator itr; itr it; it = this->buffer.begin(); for(int i = 0; i < line_num -1; ++i) { ++it; } this->buffer.insert(it, user_text); std::cout << "Cool, Your new line has been inserted." << '\n'; } std::cout << '\n'; } ``` I am getting the following compile error: ``` error: no match for ‘operator=’ in ‘it = ((editor<std::basic_string<char> >*)this)->editor<std::basic_string<char> >::buffer.std::vector<_Tp, _Alloc>::begin [with _Tp = std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > >, _Alloc = std::allocator<std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > > >, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > >*, std::vector<std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > >, std::allocator<std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > > > > >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > >*]()’ ``` I have a feeling the compiler is getting confused with my `typedef` statement above but that is how I have seen to declare the correct iterator, but for some reason it is not working correctly. Any ideas?

Original source