title: C++ template functions with the same name but different return type
body: <p>I am trying to make some file streamer that can read or write different types. Everything works except for the reading part with specific method. That method returns <code>std::unique_ptr&lt;T&gt;</code> when called and is a "wrapper" for another method that returns <code>T</code>. For some reason compiler does not use this method instead it tries to compile it with the other method (the one that returns <code>T</code>). The compilation fails because of this. I've already tried to search around internet but I can not find any accurate answer. Could you please help me with this.</p>
  
  <p>The two methods I have defined:</p>
  
  <pre><code>template &lt;typename T&gt;
  T read()
  {
       T obj;
       obj.readFromFile&lt;T&gt;();
       return std::move(obj);
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>template &lt;
    typename T,
    template&lt;typename&gt; class D,
    template&lt;typename, typename&gt; class Container
  &gt;
  typename  std::enable_if_t&lt;
    std::is_same&lt;Container&lt;T, D&lt;T&gt;&gt;, std::unique_ptr&lt;T, D&lt;T&gt;&gt;&gt;::value,
    Container&lt;T, D&lt;T&gt;&gt;
  &gt;
  read()
  {
      return std::move(std::make_unique&lt;T, D&lt;T&gt;&gt;(readFromFile&lt;T&gt;()));
  }
  </code></pre>
  
  <p>The latter method is the one that I am trying to call.</p>
  
  <p>When I write something like this:</p>
  
  <p><code>std::unique_ptr&lt;A&gt; AfromFile = fileStreamer.read&lt;std::unique_ptr&lt;A&gt;&gt;()</code></p>
  
  <p>compiler tries to compile it with the first method (<code>template &lt;typename T&gt; T read() {...}</code>) and the compilation fails. I could make this work if I made <code>unique_ptr object</code> first and than do the copy assignment to <code>*unique_ptr&lt;A&gt; object</code> but this is no good for me because i use some macro over those two functions and I cannot make <code>unique_ptr&lt;A&gt; object</code> or object A it self prior to calling the macro. Just for info I am using Visual Studio 2015.</p>
  
  <p>Is there any way to make this work without any significant modification? I also found one suggestion that basically says you have to add a pointer parameter to one function and then call it with <code>static_cast&lt;Obj&gt;(nullptr)</code> as an argument but this does not count in my example.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>Update:</strong>
  I just want to make a remark that all solutions below did work for me however the easiest way to fix my problem was solution provided by Barry.
  Thx again for helping me!</p>