title: Boost Python Runtime error when passing object of derived type from python to C++ function expecting a shared_ptr to base type
body: <p>I have a function that takes a std::shared_ptr, and I want to pass an object of Derived type to this function from python. Here's my class definitions:</p>
  
  <pre><code>struct AbstractBase {
      virtual void foo() = 0;
  };
  
  struct Derived : public AbstractBase {
      virtual void foo(){
          std::cout&lt;&lt;"Derived's foo!"&lt;&lt;std::endl;
      }
  };
  
  struct Unrelated {
      void bar(std::shared_ptr&lt;AbstractBase&gt; base_shared_ptr) {
          base_shared_ptr-&gt;foo();
      }
  };
  #endif /* CLASSES_H */
  </code></pre>
  
  <p>A simple pure C++ example does what I want:</p>
  
  <pre><code>int main()
  {
      std::shared_ptr&lt;Derived&gt; d(new Derived);
      Unrelated u;
      u.bar(d);
  }
  </code></pre>
  
  <p>output: <code>Derived's foo!</code></p>
  
  <p>Here is my Boost.Python Wrapper code:</p>
  
  <pre><code>#include &lt;boost/python.hpp&gt;
  #include "classes.h"
  
  
  BOOST_PYTHON_MODULE(shared_ptr_test) {
      using namespace boost::python;
      class_&lt;AbstractBase,std::shared_ptr&lt;AbstractBase&gt;,boost::noncopyable&gt;("AbstractBase",no_init);
  
      class_&lt;Derived,std::shared_ptr&lt;Derived&gt;,bases&lt;AbstractBase&gt;,boost::noncopyable&gt;("Derived");
  
      class_&lt;Unrelated,std::shared_ptr&lt;Unrelated&gt;,boost::noncopyable&gt;("Unrelated")
          .def("bar",&amp;Unrelated::bar);
  }
  </code></pre>
  
  <p>And here's my simple python test:</p>
  
  <pre><code>import shared_ptr_test
  
  d=shared_ptr_test.Derived()
  u=shared_ptr_test.Unrelated()
  u.bar(d)
  </code></pre>
  
  <p>To my dismay, this does not work. It compiles fine, but when I run the python script, I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 5, in &lt;module&gt;
      u.bar(d)
  Boost.Python.ArgumentError: Python argument types in
      Unrelated.bar(Unrelated, Derived)
  did not match C++ signature:
      bar(Unrelated {lvalue}, std::shared_ptr&lt;AbstractBase&gt;)
  </code></pre>
  
  <p>Changing <code>bar</code> to take a <code>shared_ptr&lt;Derived&gt;</code> fixes this, so I know that internally Boost.Python is managing the objects with <code>shared_ptr</code>s. Is there something more I need to do to get Boost.Python to realize that it is okay to pass a <code>shared_ptr&lt;Derived&gt;</code> to a function expecting a <code>shared_ptr&lt;Base&gt;</code>? </p>