what does g++ want from my code
Erez D
erez0001 at gmail.com
Wed Aug 25 12:33:29 IDT 2010
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 ?
>
> 2010/8/25 Erez D <erez0001 at 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 at cs.huji.ac.il
>> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20100825/ba217258/attachment.html>
More information about the Linux-il
mailing list