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!
You are missing a typename
:
typedef typename std::vector<T>::iterator iterator;
There are a lot of similar question. Eg take a look at the following:
std::vector<T>::iterator
is a dependent type so you need to add typename before it.
typedef typename std::vector<T>::iterator iterator;
^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.