On 04/20/2012 03:55 AM, VáclavŠmilauer wrote:
Hello,
I have a sample hierarchy of polymorphic classes (A from which B inherits).
One of them (A1, B1) is managed with boost::shared_ptr, the other one
(A2, B2) via std::shared_ptr (I defined the get_pointer template for
std::shared_ptr).
When I call f1(boost::shared_ptr<A1>) with an object B1 from python,
it is correctly upcast to the pointer to its base class and the c++
function is called. When I call f2(std::shared_ptr<A2>) with B2 argument
from python, no upcasting takes place and I get Boost.Python.Argument
error.
<snip>
Where is the problem?
I'm pretty sure this is a symptom of the fact that boost::shared_ptr is
handled specially by Boost.Python, and custom smart pointers (which is
what std::shared_ptr is considered in this case) don't have all the same
features. In particular, Boost.Python doesn't assume that custom smart
pointers have implicit upcast converters, which would be needed to do
what you want (note that some smart pointers, like boost::scoped_ptr,
don't have implicit upcast converters).
The good news is that there's an easy workaround. You just need to tell
Boost.Python that the implicit conversion exists:
implicitly_convertible<std::shared_ptr<B2>,std::shared_ptr<A2>>();
That was enough to get your example to work for me.
Jim
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig