Possible Duplicate:
Why do I need to use typedef typename in g++ but not VS?
I am defining a template class as follows
template <class T>
class MyVector : public std::vector<boost::shared_ptr<T>>
{
public:
typedef MyVector::iterator MyIter;
};
I get this error at the typedef for MyIter
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I am compiling using VS 2010, I have made sure that the includes for vector and boost::shared_ptr are present. If I remove the template T and replace it with int everything compiles without error.
What am I missing? I want to define a template class and typedef the iterator.
This question is very well answered here:
Why do I need to use typedef typename in g++ but not VS?
But long story short, you must use the keyword typename in this way:
Because in the first pass (verifying template syntax) the compiler doesn’t really know if MyVector::iterator is a type or a variable (what it is actually going to be on the specialized template). So hinting it that it is a type fixes the issue.