I've been running into the following problem inside a member function of a templated class:
#include <map>
using std::map;
template <typename A,typename B>
class C {
public:
B f(const A&,const B&) const;
private:
map<A,B> D;
};
template <typename A,typename B>
B C<A,B>::f(const A&a,const B&b) const {
map<A,B>::const_iterator x = D.find(a);
if(x == D.end())
return b;
else
return x->second;
}
When I have g++ compile this I get the following error:
Bug.C: In member function 'B C<A,B>::f(const A&, const B&) const':
Bug.C:12: error:expected ';' before 'x'
Bug.C:13: error: 'x' was not declared in this scope
However, when I make a non-templated version of the class and function, with A and B both being int it compiles without a problem. The error is a little mystifying since I can't imagine why it wants a ';' before the 'x'.