Community
Participate
Working Groups
Created attachment 176606 [details] The template that fails I have a map defined within a template, using the template parameters. The iterator is no longer properly recognized as a type. It appears that the parser thinks that it shouldn't be a type, but it is, and the parser gets confused. The relevant message is: ../main.c++:17: error: dependent-name 'std::map<Key,Val,std::less<_Key>,std::allocator<std::pair<const _Key, _Tp> > >::iterator' is parsed as a non-type, but instantiation yields a type Note that it did not work making a separate type def for the iterator. I am attaching the failing program, and the same program that works fine when it is not a template. Bob PS: Since I can't add 2 attachments, here is the good class. #include <map> #include <string> #include <utility> #include <iostream> using namespace std; class sym { public: short find (string name) { map<string, short>::iterator res = tbl.find(name); if (res == tbl.end()) return undef_val; return res -> second; } void add (string name, short val) {tbl.insert(make_pair(name, val)); } private: static short undef_val; map<string, short> tbl; }; short sym::undef_val = 0; int main(int argc, char * argv[]) { sym mytbl; string mystr = "abc"; mytbl.add(mystr, 6); short i = mytbl.find(mystr); short j = mytbl.find("def"); cout << "It ran: " << i << j << endl; }
May be not a bug See: http://stackoverflow.com/questions/3311633/nested-templates-with-dependent-scope and http://stackoverflow.com/questions/642229/why-do-i-need-to-use-typedef-typename-in-g-but-not-vs
The example code is wrong (see comment 1). In addtion to that, the error is generated by your compiler, not by CDT.