Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef vector template

I'm trying to add some typedef to my class, but the compiler reports a syntax erron on the following code:

    template<class T>
    class MyClass{
        typedef std::vector<T> storageType; //this is fine
        typedef storageType::iterator iterator; //the error is here

but the next does not work too:

        typedef std::vector<T>::iterator iterator;

I was looking for the answers on many forum but i can't find a solution or workaround for this. Thank you for your help!

like image 978
Dénes Ákos Nagy Avatar asked Feb 18 '23 19:02

Dénes Ákos Nagy


2 Answers

You are missing a typename:

typedef typename std::vector<T>::iterator iterator;

There are a lot of similar question. E.g. take a look at the following:

  • C++ template typename iterator
like image 143
nosid Avatar answered Feb 24 '23 19:02

nosid


std::vector<T>::iterator is a dependent type so you need to add typename before it.

typedef typename std::vector<T>::iterator iterator;
        ^
like image 26
Dirk Holsopple Avatar answered Feb 24 '23 18:02

Dirk Holsopple