0

I'm trying to write a function taking a range of vector iterators, but I don't know how to write a template accepting vector iterators of any kind, like vector<int>, vector<double>, vector<string> etc.

This is my function so far:

template <typename T>
void my_print(std::vector<T>::const_iterator beg, std::vector<T>::const_iterator end)
{
    while (beg != end)
    {
        std::cout << "This is element " << *beg++ << std::endl;
    }
}

and the error I'm getting:

Warning C4346: 'std::vector>::const_iterator': dependent name is not a type CppApp main.cpp 12 Error IntelliSense: no instance of function template "my_print" matches the argument list argument types are: (std::_Vector_const_iterator>>, std::_Vector_const_iterator>>) CppApp main.cpp 23

Thanks in advance for any help.

Wojtek
  • 801
  • 1
  • 9
  • 13

0 Answers0