Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Apart from what @dag has mentioned, a function definition without parameter name finds its usage in template specialization. I know you have mentioned that there are no templates in the example you have posted, but for sake of completeness i'd like to post this use case:</p> <p>Suppose you have defined an <code>erase</code> function for <code>std</code> containers. But you want different <code>erase_helper</code> to do the actual work based on the container type. A common and acceptable practice is to use <code>traits</code>.</p> <pre><code>// Tags for containers struct vector_tag {}; struct map_tag {}; // Trait class template &lt;typename C&gt; struct container_traits; // Specialization of trait class template &lt;typename T, typename A&gt; struct container_traits&lt;std::vector&lt;T, A&gt;&gt; { typedef vector_tag category; }; template &lt;typename K, typename V, typename C, typename A&gt; struct container_traits&lt;std::map&lt;K, V, C, A&gt;&gt; { typedef map_tag category; }; // Helper function template &lt;typename Container, typename X&gt; void erase_helper(Container&amp; c, const X&amp; x, vector_tag) // &lt;-- no param name { // Erase element from vector } template &lt;typename Container, typename X&gt; void erase_helper(Container&amp; c, const X&amp; x, map_tag) // &lt;-- no param name { // Erase element from map } // Function interface template &lt;typename Container, typename X&gt; void erase(Container&amp; c, const X&amp; x) { erase_helper(c, x, typename container_traits&lt;Container&gt;::category()); } </code></pre> <p>You can see here, <code>erase_helper</code> has third parameter without a name. Type of parameter tells compiler to pick correct function at template instantiation phase.</p>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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