1

Here's my code:

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);
}

I get the error 'iterator is not a type'.

I tried adding std:: or container_type:: before iterator, didn't help. I tried defining the template as template <typename container_type<typename T> > and the iterators as container_type<T>::iterator, no luck. What's wrong?

user3150201
  • 1,663
  • 4
  • 21
  • 26

2 Answers2

6

I think you mean the following

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

Take into account that in any case your function is wrong because after inserting an element in the container iterators can be invalid.

Vlad from Moscow
  • 224,104
  • 15
  • 141
  • 268
1

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

container_type::iterator is a dependent name, therefore you need the typename keyword before it to treat it as a type (typename container_type::iterator). That is explained in depth here.

Community
  • 1
  • 1
Columbo
  • 57,033
  • 7
  • 145
  • 194