Déclaration d'iterator dans template
Bonjour,
si quelqu'un pouvait m'éclairer vis à vis de ce code de template :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
template<typename T, class C>
class MTest
{
public:
MTest() {}
~MTest() {}
C* find(T t)
{
std::map<T, C*>::iterator it;
if ((it = mymap.find(t)) == mymap.end())
return (0);
return (it->second);
}
protected:
std::map<T, C*> mymap;
}; |
Cette version compilée simplement avec g++ sans option me renvoie :
Code:
1 2 3 4
|
Test.hh:18: error: expected ; before it
Test.hh:20: error: it was not declared in this scope
Test.hh:23: error: it was not declared in this scope |
Et quand je réécris la méthode find de cette manière :
Code:
1 2 3 4 5 6 7 8
|
C* find(T t)
{
if ((mymap.find(t)) == mymap.end())
return (0);
return (mymap.find(t)->second);
} |
=> dans ce cas je n'ai pas d'erreur, un problème vis à vis de la déclaration de l'iterator ? quelqu'un a une idée ?
=> g++ (Debian 4.4.5-8) 4.4.5