Hi,
I am getting the error C2027:Use of undefined type 'T' when I tried to
compile some code in visual c++7.1 that went fine in Visual c++6.0.
Below is the relevant code where the error has come.
------------------------------------------------------------------------------------------------------------------------------------
template <class T>
class MCS_PersistentList
{
public:
/* typedef std::list<T> List;*/
typedef std::list<class T> List;/*above line modified to the current
line to resolve C2146*/
typedef List::iterator iterator;
typedef List::const_iterator const_iterator;
.
.
.
}
class MCS_ADH_Device_Cfg
{
public:
int deviceNum;
.
.
.
}
typedef MCS_PersistentList<MCS_ADH_Device_Cfg> ADH_ConfigFile;
ADH_ConfigFile::iterator it;
int x = it->deviceNum;<------Error points to this line
--------------------------------------------------------------------------------------------------------------------------------------
Any kind of help is appreciated.
Thanks in advance.
Best Regards,
Rohini Chandra
Tamas Demjen - 08 May 2006 18:33 GMT
> template <class T>
> class MCS_PersistentList
[quoted text clipped - 6 lines]
> typedef List::iterator iterator;
> typedef List::const_iterator const_iterator;
The standard requires that you use the "typename" keyword to refer to
type names in your template:
template <class T>
class MCS_PersistentList
{
public:
typedef std::list<typename T> List;
// you must tell the compiler that T is a type name
typedef typename List::iterator iterator;
typedef typename List::const_iterator const_iterator;
// you must tell the compiler that List::iterator and
// List::const_iterator are type names
Tom
rohinichandrap@gmail.com - 09 May 2006 09:32 GMT
Hi Tamas,
Thank you very much for the suggestion.
It worked and the error does not show up.
Best Regards,
Rohini Chandra