"using" keyword – passing iterator to function

Issue

I am writing a class Sequence. Its constructor takes two templated vector iterators as arguments.
Here is the code:

template <class T> using ConstIterator_t = typename std::vector<T>::const_iterator;
template <class T>
class Sequence{
public:
Sequence(ConstIterator_t start, ConstIterator_t end);
//rest of the code
};

When I compile the code it shows me this error: expected ‘)’ before ‘start’.

Could you please help me?
Many thanks in advance.

[edit] By the way, when I change ConstIterator_t with its defintion, the error disappears.

Solution

ConstIterator_t is a template (an alias template) and you need to specify template argument for it. E.g.

template <class T> using ConstIterator_t = typename std::vector<T>::const_iterator;
template <class T>
class Sequence{
public:
    Sequence(ConstIterator_t<T> start, ConstIterator_t<T> end);
    // same as
    Sequence(typename std::vector<T>::const_iterator start, typename std::vector<T>::const_iterator end);
};

Answered By – songyuanyao

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.