[C++-sig] wrapper and shared_ptr - how to combine?

Leonard Ritter paniq at paniq.org
Sat Nov 15 17:11:30 CET 2008

i am wrapping an abstract class "Actor" which is to be implemented partially
in Python, using a wrapper class that looks like this:

class PyActor : public Actor, public wrapper<Actor> {

the boost.python export code looks like this:

class_<PyActor, boost::noncopyable>("Actor");

this would be all good and well, until I decided to pass back Actor pointers
from methods e.g. like Actor::get_parent(), which have to resolve back to
original python objects, for which the FAQ suggests using shared_ptr, if
altering the underlying code was possible - which it is.

so there is now a method in Actor declared like this:

// assumed: typedef boost::shared_ptr<Actor> ActorPtr;

ActorPtr Actor::get_parent();

unfortunately calling that method gives me a new wrapped Actor python object
- not exactly what the FAQ promised. but I read that the shared_ptr<> has to
be declared as the object holder, like this:

class_<PyActor, ActorPtr, boost::noncopyable("Actor");

which I did, but that gives me a compiler error if Actor is abstract, and if
I declare it non-abstract, calls to wrapping PyActor methods fail in Python.
I guess that this approach does not work with wrapper classes, or the syntax
is different.

how do I have to do it? I searched through the mailing list but found
nothing viable so far.

thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081115/1798b32d/attachment.htm>

More information about the Cplusplus-sig mailing list