#include <list>
template < class TYPE >
class CIndex : protected std::list < TYPE >
{
public:
typedef std::list < TYPE >::iterator CIndexIt;
typedef std::list < TYPE >::difference_type CIndexDiff;
The error happens in the last line of the above code.
I’ve seen this and the msdn page but both don’t solve my error.
Anyone knows what could be causing the problem?
EDIT:
The reason the first link’s solution didn’t work was because although adding typename worked for the above code, it didn’t work for the below code:
#include<hash_map>
class CWItems
{
typedef stdext::hash_map < unsigned long, CWksItem* > CItem;
CItem mItems;
So I thought I was doing the wrong thing by adding typename everywhere. Using typename after the typedef in this code caused this error:
error C2899: typename cannot be used outside a template declaration
Without typename, the error shown is error C4430: missing type specifier - int assumed. Note: C++ does not support default-int, at the CItem mItems; line.
You need to add the
typenamekeyword becausestd::list<TYPE>::iteratorandstd::list<TYPE>::difference_typeare dependent names:See http://pages.cs.wisc.edu/~driscoll/typename.html for more information.