template <class a, class b> class c
{ private: b defaultVal; public: std::map<a,b> mymap; const b &func(a idx) { typename std::map<a,b>::iterator it(mymap.find(idx)); if (it!=mymap.end()) return it->second; else return defaultVal; } }; The compiler is not sure std::map<a,b>::iterator is a typename or a value. 2010/8/25 Erez D <erez0...@gmail.com> > hi > > i am compiling the following code: > > 1:#include <map> > 2: > 3:template <class a, class b> > 4:class c > 5:{ > 6: private: > 7: b defaultVal; > 8: public: > 9: std::map<a,b> mymap; > 10: const b &func(a idx) > 11: { > 12: std::map<a,b>::iterator it=mymap.find(a); > 13: if (it!=mymap.end()) > 14: return it->second; > 15: else > 16: return defaultVal; > 17: } > 18:}; > ... > ... > > compiling it (under cygwin) , i get the following: > > $ g++ -c -o kaka.o kaka.cpp > kaka.cpp: In member function 'const b& c<a, b>::func(a)': > kaka.cpp:12: error: expected `;' before 'it' > kaka.cpp:13: error: 'it' was not declared in this scope > > > what's wrong ? > > _______________________________________________ > Linux-il mailing list > Linux-il@cs.huji.ac.il > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > >
_______________________________________________ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il