Why does casting a function to a function type that is identical except for return type fail?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/290038/is-the-return-type-part-of-the-function-signature">Is the return type part of the function signature?</a>  </p>
</blockquote>



<p>Following up on a related but tangential question ( <a href="http://stackoverflow.com/questions/13684264/how-to-disambiguate-function-templates-that-differ-only-by-return-type">How to disambiguate function templates that differ only by return type?</a> ), I would like to ask a question related to the fact that the <em>return type</em> of a function is not considered to be part of the signature of a function.</p>

<p>Consider the following code:</p>

<pre><code>#include &lt;iostream&gt;

int foo()
{
    return 0;
}

int main()
{
    long n = static_cast&lt;long(&amp;)()&gt;(foo)(); // Error: incorrect return type
    int p = static_cast&lt;int(&amp;)()&gt;(foo)(); // Compiles just fine 
}
</code></pre>

<p>The line of code noted above results in a compilation error, because the <em>return</em> type of the function type to which <code>foo</code> is being cast does not match the <em>return</em> type of the function <code>foo</code>.</p>

<p>But I thought the return type of a function does not play a role in the signature of the function!</p>

<p>According to a certain line of thinking, since the function signature <code>long(&amp;)()</code> matches the signature of <code>foo</code>, the cast of <code>foo</code> to a function of this type should succeed.</p>

<p>However, the cast does not succeed.  Where does the reasoning go wrong?  If the cast cannot fail due to the function signature, then why does the cast fail?</p>
