title: Why is it illegal for non-templated functions to have same name and arguments but different return types? (but legal for template functions?)
body: <p>I looked a few related stack overflow threads such as <a href="https://stackoverflow.com/questions/31391172/this-case-of-template-function-overloading-eludes-my-understanding">This case of template function overloading eludes my understanding</a></p>
  
  <p>and </p>
  
  <p><a href="https://stackoverflow.com/questions/442026/function-overloading-by-return-type">Function overloading by return type?</a></p>
  
  <p>but neither seem to give me precisely the answer I'm looking for, at least not in a way that has been easy for me to interpret.</p>
  
  <p>My question boils down to this: why, from both a design and technical standpoint, is it legal to do this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  template&lt;class T&gt;
  void func(){
      cout &lt;&lt; "Compiler inferred from void return value!\n";
  }
  
  template&lt;class T&gt;
  int func(){
      cout &lt;&lt; "Compiler inferred from int return value!\n";
      return 0;
  }
  
  int main(){
      void (*thisFunc)()=func&lt;int&gt;;
      int (*thatFunc)()=func&lt;int&gt;;
      thisFunc();
      thatFunc();
  }
  </code></pre>
  
  <p>But not this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void func(){
      cout &lt;&lt; "You won't see this because it won't compile!\n";
  }
  
  int func(){
      cout &lt;&lt; "Nor this one!\n";
      return 0;
  }
  
  int main(){
      void (*thisFunc)()=func;
      int (*thatFunc)()=func;
      thisFunc();
      thatFunc();
  }
  </code></pre>
  
  <p>It is worth mentioning that the first example won't compile if I do not explicitly give func an arbitrary template parameter when initializing thisFunc and thatFunc. The only other difference between the two is that the first one has func templated by a type which is completely immaterial, except that it is apparently allowing me to overload by return type. The compiler is even able to make an inference in that case on which function to call, making the illegality of function overloading by return type in c++ somewhat baffling to me. In any case, it's a neat trick I guess.</p>
  
  <p>EDIT: The thing that bothers me the most is the inconsistency: I would think very long and hard before I genuinely considered overloading by return type, but if the "fix" for someone who <em>wants</em> to overload by return type is to simply add a meaningless template parameter or apparently wrap the functions inside namespaces, then I would think either C++ should either more or less strict about what it considers ambiguous. Is there a compelling reason why templates and namespaces need this functionality to work correctly? Is there an example of desirable code that could not work if, for instance, templates were not allowed to disambiguate code as in my example? I am asking from a language design standpoint, not a compiler compliance standpoint.</p>