Note that there are some explanatory texts on larger screens.

plurals
  1. POAcademic question: typename
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/642229/why-do-i-need-to-use-typedef-typename-in-g-but-not-vs">Why do I need to use typedef typename in g++ but not VS?</a> </p> </blockquote> <p>Hi, recently I accounted with a "simple problem" of porting code from VC++ to gcc/intel. The code is compiles w/o error on VC++:</p> <pre><code>#include &lt;vector&gt; using std::vector; template &lt;class T&gt; void test_vec( std::vector&lt;T&gt; &amp;vec) { typedef std::vector&lt;T&gt; M; /*==&gt; add here typename*/ M::iterator ib=vec.begin(),ie=vec.end(); }; int main() { vector&lt;double&gt; x(100, 10); test_vec&lt;double&gt;(x); return 0; } </code></pre> <p>then with g++ we have some unclear errors:</p> <pre><code> g++ t.cpp t.cpp: In function 'void test_vec(std::vector&lt;T, std::allocator&lt;_CharT&gt; &gt;&amp;)': t.cpp:13: error: expected `;' before 'ie' t.cpp: In function 'void test_vec(std::vector&lt;T, std::allocator&lt;_CharT&gt; &gt;&amp;) [with T = double]': t.cpp:18: instantiated from here t.cpp:12: error: dependent-name 'std::M::iterator' is parsed as a non-type, but instantiation yields a type t.cpp:12: note: say 'typename std::M::iterator' if a type is meant </code></pre> <p>If we add <strong>typename</strong> before iterator the code will compile w/o pb.</p> <p>If it is possible to make a compiler which can understand the code written in the more "natural way", then for me is unclear why we should add typename? Which rules of "C++ standards"(if there are some) will be broken if we allow all compilers to use without "typename"?</p> <p>kind regards Arman.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload