On 22 Dez., 14:42, Bertwim <b...@xs4all.nl> wrote:
> Hi,
>
> I can't understand the compiler's error message in the following
> template definition:
>
> In a header file (.h), I have declared
> ==================================
> template <class T>
> class symtblpp
> {
> private:
> * * typedef std::map< std::string, T > maptype;
> * * maptype _map;
> public:
> * * T* lookup( const std::string& );};
>
> ===================================
>
> In the implementation file (.cpp), the member 'lookup' is defined:
> =================================
> template <class T>
> T* symtblpp<T>::lookup( const std::string& key )
> {
> * * maptype::iterator it = _map.find( key );
> * * return &(*it);}
>
> ================================
> The error message is (++, 4.3.1)
>
> 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 declaration.
> Can somebody explain to me what I do wrong?
>
> Tanks in advance.
> Bertwim
Another hint (the typename thing is already explained well): leading
underscores are reserved for compiler usage. E. g. Andrei Alexandrescu
prefers trailing underscores for members. I would recommend this, too.
Or use the MS style "m_" prefix...
br
Juergen