error C2027:Use of undefined type 'T'

R

rohinichandrap

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
 
T

Tamas Demjen

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;

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
 
R

rohinichandrap

Hi Tamas,

Thank you very much for the suggestion.
It worked and the error does not show up.

Best Regards,
Rohini Chandra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top