Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You want to declare those parameters</p> <pre><code>template&lt;template &lt;class T, class Allocator&gt; class listPlaceholder, class T, class Allocator&gt; void function(listPlaceholder&lt;T, Allocator&gt; param) { // do something with every element in param (I actually need to know it's a list) typename listPlaceholder&lt;T, Allocator&gt;::iterator current = param.begin(); typename listPlaceholder&lt;T, Allocator&gt;::iterator end = param.end(); do { function&lt;T&gt;(*current); } while (++current != end); } </code></pre> <p>The names you used in the formal parameter list have no meaning. You also forgot to use <code>listPlaceholder</code> actually. But I'm assuming that was accidental. </p> <p>As another poster said, you also need the <code>typename</code> keyword because the names are <a href="https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-template-and-typename-on-dependent-names">dependent names</a>.</p> <p>For why the names in the formal list are meaningless, compare it to function pointers:</p> <pre><code>void f(void (*p)(int t, int allocator), int t, int allocator) { p(t, allocator); } void g(int a, int b) { } int main() { f(&amp;g, 0, 1); } </code></pre> <p>What is important is only the type of the parameters, and I could have written <code>void(*p)(int, int)</code> too. In your case, what is important is only that both parameters are type parameters. So you could have written the template template parameter also as <code>template&lt;class, class&gt; class listPlaceholder</code> too, completely equivalent. </p> <p>Last but not least, I would like to emphasize that you have <em>not</em> specialized <code>function</code>, but you have overloaded it with another template. So, both <code>function</code>s are two completely different function templates. </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