Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends if the function is a <em>function template</em> or not. </p> <p>In <strong>C++ Templates -- the complete guides</strong>, Jusuttis provides a different definition of that given in the C++ standard, but with equivalent consequences:</p> <p>We define the signature of a function as the the following information:</p> <ol> <li>The <em>unqualified name</em> of the function</li> <li>The <em>class</em> or <em>namespace</em> scope of that name, and if the name has internal linkage, the translation unit in which the name is declared</li> <li>The <code>const</code>, <code>volatile</code>, or <code>const volatile</code> qualification of the function</li> <li>The <em>types</em> of the function parameters</li> <li><strong>its return <em>type</em>, if the function is generated from a function template</strong></li> <li>The <em>template parameters</em> and the <em>template arguments</em>, if the function is generated from a function template</li> </ol> <p>As <strong>litb</strong> suggested, it's worth to clarify why the return type is part of the signature of a template function. </p> <blockquote> <p>Functions can coexist in a program if they have distinct signatures.</p> </blockquote> <p>. That said, if the return type is a template parameter:</p> <pre><code>template &lt;typename T&gt; T foo(int a) {return T();} </code></pre> <p>it's possibile to instantiate two function which differ only in the return type:</p> <pre><code>foo&lt;int&gt;(0); foo&lt;char&gt;(0); </code></pre> <p>Not only: as rightly reported by <strong>litb</strong>, it is also possible to overload two template functions, which differ only in the return type, even if the return type is not a dependent name. Here's his example:</p> <pre><code>template&lt;class T&gt; int foo(T) {} template&lt;class T&gt; bool foo(T) {} // at the instantiation point it is necessary to specify the cast // in order not to face ambiguous overload ((int(*)(char))foo&lt;char&gt;)('a'); </code></pre>
    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. 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