weird parse error in template class

  • Thread starter Manuel Maria Diaz Gomez
  • Start date
M

Manuel Maria Diaz Gomez

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
========================================================================
 
G

Gianni Mariani

Manuel said:
Hi everybody,

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

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.
 

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

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,462
Latest member
ChanaLipsc

Latest Threads

Top