Boost logo

Boost Users :

From: Nat Goodspeed (ngoodspeed_at_[hidden])
Date: 2004-10-30 09:03:24


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of John Meinel
> Sent: Saturday, October 30, 2004 9:24 AM
> To: boost-users_at_[hidden]
> Subject: [Boost-users] shared_ptr<> w/ Boost::Python
>
> In the boost::python tutorial, they talk about when you return a raw
> reference or pointer, you need to wrap it to manage lifetime of the
> object.
> http://www.boost.org/libs/python/doc/tutorial/doc/call_policies.html
>
> In the beginning of that page, they talk about how smart pointers are
> better for defining the scope and lifetime of objects, but sometimes
raw
> pointers are necessary. I've gotten pretty good about when to
> manage_new_object, or return_internal_reference, etc.
>
> However, now that I have changed my return functions to actually
return
> a smart pointer, it doesn't seem like I should need to wrap the return
> value anymore. Only now, when I try to do a "get" it gives me the
error:
>
> " No to_python (by-value) converter found for C++ type: class
> boost::shared_ptr<class mine> "
>
> I have a converter for "class mine". I actually thought that the
> lifetime managers were using a shared_ptr, so if I did it myself, it
> would just be transparent.

[Nat] We tell boost::python the smart pointer type we're using, like
this:

    class_<DrawableInterface, DrawablePtr, boost::noncopyable>
("DrawableInterface", no_init)
    ;

where DrawablePtr is a typedef for the smart pointer type.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net