Overload method for unique_ptr and shared_ptr is ambiguous with polymorphism : <p>Coding stuff after taking the hint from my <a href="https://stackoverflow.com/questions/53444116/ownership-with-a-physical-representation">previous question</a>'s answer, I ran into an issue with overloading Scene::addObject.</p>

<p>To reiterate the relevant bits and make this self contained, with the least details possible:</p>

<ul>
<li>I have a hierarchy of objects inheriting from <code>Interface</code> of which there are <code>Foo</code>s and <code>Bar</code>s;</li>
<li>I have a <code>Scene</code> which owns these objects;</li>
<li><code>Foo</code>s are to be <code>unique_ptr</code>s and <code>Bar</code>s are to be <code>shared_ptr</code>s in my main (for reasons explained in the previous question);</li>
<li>the <code>main</code> passes them to the <code>Scene</code> instance, which takes ownership.</li>
</ul>

<p>Minimal code example is <a href="https://coliru.stacked-crooked.com/a/fbd879ab9d4beb69" rel="noreferrer">this</a>:</p>

<pre><code>#include &lt;memory&gt;
#include &lt;utility&gt;

class Interface
{
public:
  virtual ~Interface() = 0;
};

inline Interface::~Interface() {}

class Foo : public Interface
{
};

class Bar : public Interface
{
};

class Scene
{
public:
  void addObject(std::unique_ptr&lt;Interface&gt; obj);
//  void addObject(std::shared_ptr&lt;Interface&gt; obj);
};

void Scene::addObject(std::unique_ptr&lt;Interface&gt; obj)
{
}

//void Scene::addObject(std::shared_ptr&lt;Interface&gt; obj)
//{
//}

int main(int argc, char** argv)
{
  auto scn = std::make_unique&lt;Scene&gt;();

  auto foo = std::make_unique&lt;Foo&gt;();
  scn-&gt;addObject(std::move(foo));

//  auto bar = std::make_shared&lt;Bar&gt;();
//  scn-&gt;addObject(bar);
}
</code></pre>

<p>Uncommenting the commented lines results in:</p>

<pre><code>error: call of overloaded 'addObject(std::remove_reference&lt;std::unique_ptr&lt;Foo, std::default_delete&lt;Foo&gt; &gt;&amp;&gt;::type)' is ambiguous

   scn-&gt;addObject(std::move(foo));

                                ^

main.cpp:27:6: note: candidate: 'void Scene::addObject(std::unique_ptr&lt;Interface&gt;)'

 void Scene::addObject(std::unique_ptr&lt;Interface&gt; obj)

      ^~~~~

main.cpp:31:6: note: candidate: 'void Scene::addObject(std::shared_ptr&lt;Interface&gt;)'

 void Scene::addObject(std::shared_ptr&lt;Interface&gt; obj)

      ^~~~~
</code></pre>

<p>Uncommenting the shared and commenting the unique stuff also compiles, so I take it the problem is, like the compiler says, in the overload. However I need the overload as both these types will need to be stored in some kind of collection, and they are indeed kept as pointers to base (possibly all moved into <code>shared_ptr</code>s).</p>

<p>I'm passing both by-value because I want to make clear I'm taking ownership in <code>Scene</code> (and upping the reference counter for the <code>shared_ptr</code>s). Not really clear to me where the issue lies at all, and I couldn't find any example of this elsewhere.</p>
