weird parse error in template class



 DEVELOP > c-Plus-Plus > weird parse error in template class

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Manuel Maria Diaz Gomez"
Date: 28 May 2004 12:30:28 PM
Object: weird parse error in template class
Hi everybody,
maybe you can give me a hint about the following problem:
I have a simple template class that stores pointers to variables in a map,
and publish the actual values when requested.
template<typename T>
class HighLevelMonitor {
public:
void declareMyVar(string, T*);
void publishAll();
private:
map<string, T*> monVarContainer;
};
In the following implementation, I get a " parse error before = " when
compiling coming form the line:
map<string, T*>::iterator it = monVarContainer.begin();
\*-------------------------------------------------*\
template <typename T>
void HighLevelMonitor<T>::publishAll()
\*-------------------------------------------------*\
{
cout <<"------------publishAll()------------" << endl;
map<string, T*>::iterator it = monVarContainer.begin();
for(; it != monVarContainer.end(); it++ ){
cout << it->first << " = " << *(it->second) << endl;
}
cout <<"---------------------------------------" << endl;
}
Any clue about why I get this error??
Regards
Manuel
--
========================================================================
Manuel Diaz-Gomez | ATLAS Bldg. 32/SB-008 tel. +41 22 76 76304
CERN EP Division
CH-1211 Geneva 23
SWITZERLAND
========================================================================
.

User: "Gianni Mariani"

Title: Re: weird parse error in template class 28 May 2004 12:53:00 PM
Manuel Maria Diaz Gomez wrote:

Hi everybody,

maybe you can give me a hint about the following problem:

....


map<string, T*>::iterator it = monVarContainer.begin();

typename map<string, T*>::iterator it = monVarContainer.begin();


Any clue about why I get this error??

When parsing a template, the compiler can't tell if what you're
referencing is a type or not and so needs some help. It is required by
the standard that you use "typename" to prefix the type expression when
the template is unable to determine the type.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER