<div dir="ltr"><span style=" color:#808000;">template</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;"><</span><span style=" color:#808000;">class</span><span style=" color:#c0c0c0;"> </span>a<span style=" color:#000000;">,</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">class</span><span style=" color:#c0c0c0;"> </span>b<span style=" color:#000000;">></span>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#808000;">class</span><span style=" color:#c0c0c0;"> </span>c</pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000000;">{</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">private</span><span style=" color:#000000;">:</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span>b<span style=" color:#c0c0c0;"> </span>defaultVal<span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">public</span><span style=" color:#000000;">:</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span>std<span style=" color:#000000;">::</span>map<span style=" color:#000000;"><</span>a<span style=" color:#000000;">,</span>b<span style=" color:#000000;">></span><span style=" color:#c0c0c0;"> </span>mymap<span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span>b<span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">&</span>func<span style=" color:#000000;">(</span>a<span style=" color:#c0c0c0;"> </span>idx<span style=" color:#000000;">)</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">{</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">typename</span><span style=" color:#c0c0c0;"> </span>std<span style=" color:#000000;">::</span>map<span style=" color:#000000;"><</span>a<span style=" color:#000000;">,</span>b<span style=" color:#000000;">>::</span>iterator<span style=" color:#c0c0c0;"> </span>it<span style=" color:#000000;">(</span>mymap<span style=" color:#000000;">.</span>find<span style=" color:#000000;">(</span>idx<span style=" color:#000000;">));</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">if</span><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">(</span>it<span style=" color:#000000;">!=</span>mymap<span style=" color:#000000;">.</span>end<span style=" color:#000000;">())</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> </span>it<span style=" color:#000000;">-></span>second<span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">else</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> </span>defaultVal<span style=" color:#000000;">;</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#000000;">}</span></pre>
<pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000000;">};</span></pre><pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
<span style=" color:#000000;"><br></span></pre>The compiler is not sure std::map<a,b>::iterator is a typename or a value.<div><br><div class="gmail_quote">2010/8/25 Erez D <span dir="ltr"><<a href="mailto:erez0001@gmail.com">erez0001@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">hi<br><br>i am compiling the following code:<br><br>1:#include <map><br>2:<br>3:template <class a, class b><br>
4:class c<br>5:{<br>6: private:<br>7: b defaultVal;<br>8: public:<br>
9: std::map<a,b> mymap;<br>10: const b &func(a idx)<br>11: {<br>12: std::map<a,b>::iterator it=mymap.find(a);<br>13: if (it!=mymap.end())<br>
14: return it->second;<br>15: else<br>16: return defaultVal;<br>17: }<br>18:};<br>...<br>...<br><br>compiling it (under cygwin) , i get the following:<br>
<br>$ g++ -c -o kaka.o kaka.cpp<br>kaka.cpp: In member function 'const b& c<a, b>::func(a)':<br>kaka.cpp:12: error: expected `;' before 'it'<br>kaka.cpp:13: error: 'it' was not declared in this scope<br>
<br><br>what's wrong ?<br></div>
<br>_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
<br></blockquote></div><br></div></div>