Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

template parameter not recognise in typedef?

Hi,
I am in the process of migrating a lib from VS6 to VS2005 and get a cryptic
syntax error.

#include "stdafx.h"
#include <set>
#include <map>
// using std::map; // uncommenting doesn't help
template <class EL_TYPE>
class mat
{
};
template <class EL_TYPE>
class thin_mat : public mat<EL_TYPE>
{
private:
typedef std::map<int,EL_TYPE> DATATYPE;
// if i change EL_TYPE to int, then no error below
// compiler doesn't complain about the typedef either way
typedef std::set<size_t> INDEXSET; //ok
typedef std::map<size_t,INDEXSET> INDEXSETMAP; //ok

enum
{
INDEXSETS_INSERT = 0x01,
INDEXSETS_REMOVE = 0x02
};

public:
typedef INDEXSET::iterator iteratorY; // ok
typedef DATATYPE::iterator iterator; // <<< here the compiler spits
typedef INDEXSET::iterator iteratorX; // ok
};

int _tmain(int argc, _TCHAR* argv[])
{
thin_mat<int> imat;
return 0;
}

Is this a compliance issue, where VS6 was too sloppy and compiled non-
standard code, or is it an issue in VS2005?

BTW: I tried renaming "DATATYPE" to "asdf", I tried using std::map -statement, I tried to rename iterator to myIter, all no good...

Any help is much appreciated.

Cheers,

D
[1532 byte] By [drkybelk] at [2007-11-11 9:58:51]
# 1 Re: template parameter not recognise in typedef?
I think you should try adding of typename keyword:
template <class EL_TYPE>
class thin_mat : public mat<EL_TYPE>
{
private:
typedef std::map<int,EL_TYPE> DATATYPE;

. . .

typedef typename DATATYPE::iterator iterator;

. . .
};
It arises from improvements added to C++ standards. It tells the compiler that an unknown identifier -- DATATYPE::iterator -- is a type.

I hope this helps.
Viorel at 2007-11-11 20:59:42 >
# 2 Re: template parameter not recognise in typedef?
Hi thanks a bunch!
I had to pull my hair out. I'll try it in the evening.
Cheers,

D
drkybelk at 2007-11-11 21:00:36 >
# 3 Re: template parameter not recognise in typedef?
Yes, it's a missing typename. DATATYPE contains a dependent name, i.e. EL_TYPE. The compiler accepts the other typdefs without the typename keywords because they don't have dependent names: all of them use int, size_t etc., which are built-in types.
Danny at 2007-11-11 21:01:41 >