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

Leonard Ritter paniq at paniq.org
Sat Nov 15 20:48:13 CET 2008

I think I know what the issue is, and it indeed relates to a piece of code I
have not posted yet.

void Actor::add(const ActorPtr &actor) {
    actor->parent = ActorPtr(this);

Actor is a tree element with children and a parent pointer. I guess that
assigning ActorPtr(this) appears to construct a new pointer for an object
that is already registered to boost.python.

On Sat, Nov 15, 2008 at 7:07 PM, Leonard Ritter <paniq at paniq.org> wrote:

> yes, that's what i want. what details do you need? i mean, the problem
> posted is quite generic. i want to pass shared_ptr's of abstract classes
> with overridable methods back and forth from c++ to python and back. is this
> supposed to work, if yes, how?
> On Sat, Nov 15, 2008 at 5:20 PM, Stefan Seefeld <seefeld at sympatico.ca>wrote:
>> Leonard Ritter wrote:
>>> 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.
>> Please post specific code as well as specific error messages. It sounds as
>> if you expect those methods to return references to existing (shared)
>> objects, while boost.python expects by-value passing, i.e. wants to make
>> copies. But without more information this is just a guess.
>> Regards,
>>      Stefan
>> --
>>     ...ich hab' noch einen Koffer in Berlin...
>> _______________________________________________
>> Cplusplus-sig mailing list
>> Cplusplus-sig at python.org
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081115/821092d8/attachment-0001.htm>

More information about the Cplusplus-sig mailing list