By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

weird parse error in template class

P: n/a
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
================================================== ======================
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.