[C++-sig] Loss of polymorphism with std::auto_ptr

Pertti Kellomäki pk at cs.tut.fi
Wed Feb 14 20:45:44 CET 2007


I've followed the recipe for transfering ownership at
<http://www.boost.org/libs/python/doc/v2/faq.html#ownership>.
Everything works nicely, except that I seem to lose polymorphism.

Let's say I have a base class A and a derived class A1, and
class B which has a member function set_a(A*). If I wrap
B::set_a() using an auto_ptr as suggested in the FAQ, and try
to call it from Python with an A1 object, I get the following
error:

Boost.Python.ArgumentError: Python argument types in
     B.set_a(B, A1)
did not match C++ signature:
     set_a(B {lvalue}, std::auto_ptr<A>)

I know how to fix this by creating another wrapper for set_a
that takes std::auto_ptr<A1> and binding it to "set_a" in Python.
However, I would like to avoid this if possible, since the
number of wrappers can grow quite large.

Any suggestions as to how to avoid the per subclass wrappers?

I have attached a small but complete example.
-- 
Pertti
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testing.cpp
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070214/2083d699/attachment.txt>


More information about the Cplusplus-sig mailing list