what does g++ want from my code

what does g++ want from my code

Oleg Goldshmidt pub at goldshmidt.org
Wed Aug 25 13:53:11 IDT 2010


2010/8/25 Erez D <erez0001 at gmail.com>:
>
>
> On Wed, Aug 25, 2010 at 12:08 PM, Elazar Leibovich <elazarl at gmail.com>
> wrote:
>>
>> 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.
>
> how do i sove that ? can you give a solution ?

I think you missed the fact that Elazar gave a solution - the above is
NOT identical to what you sent:

1. uses the proper argument (idx, not a) to find()
2. adds typename


-- 
Oleg Goldshmidt | pub at goldshmidt.org



More information about the Linux-il mailing list