| 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.
.
|
|
|
|

|
Related Articles |
|
|