Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Did you actually try this code? It works fine on gcc with a small tweak <code>std::vector&lt;T&gt;::const_iterator</code>, needs to be declared as <code>typename std::vector&lt;T&gt;::const_iterator</code></p> <p>You may be better off with using std::copy and std::ostream_iterator.</p> <p>EDIT: <strong>types, dependent types and typename</strong> Can't fit it all in the comments, so here goes (btw. this is my understanding and I could be off by a country mile - if so please correct me!)...</p> <p>I think this is best explained with a simple example..</p> <p>Let's assume you have a function foo</p> <pre><code>template &lt;typename T&gt; void foo() { T::bob * instofbob; // this is a dependent name (i.e. bob depends on T) }; </code></pre> <p>Looks okay, and typically you may do this</p> <pre><code>class SimpleClass { typedef int bob; }; </code></pre> <p>And call</p> <pre><code>foo&lt;SimpleClass&gt;(); // now we know that foo::instofbob is "int" </code></pre> <p>Again, seems self explanatory, however some nuser comes along and does this</p> <pre><code>class IdiotClass { static int bob; }; </code></pre> <p>Now</p> <pre><code>foo&lt;IdiotClass&gt;(); // oops, </code></pre> <p>What you have now is an expression (multiplication) as IdiotClass::bob resolves to a non-type!</p> <p>To the human, it's obvious that this is stupid, but the compiler has no way of differentiating between types vs. non-types, and by default in C++ (and I think this is where compilers differ), <strong>all</strong> qualified <em>dependent names</em> (i.e. T::bob) will be treated as <em>non-type</em>. To <em>explicitly</em> tell the compiler that the dependent name is a real type, you must specify the <code>typename</code> keyword - </p> <pre><code>template &lt;typename T&gt; void foo() { typedef typename T::bob *instofbob; // now compiler is happy, it knows to interpret "bob" as a type (and will complain otherwise!) }; </code></pre> <p>This applies even if it is a <code>typedef</code>. i.e.</p> <pre><code>template &lt;typename T&gt; void foo() { typedef typename T::bob local_bob; }; </code></pre> <p>Is that any clearer?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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