Home > Mobile >  "using" keyword - passing iterator to function
"using" keyword - passing iterator to function

Time:09-25

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.

CodePudding user response:

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