[C++-sig] returning pointer to instance and object ownership
Roman Yakovenko
roman.yakovenko at gmail.com
Fri Aug 22 11:27:10 CEST 2008
On Thu, Aug 21, 2008 at 10:51 PM, Max Ivanov <ivanov.maxim at gmail.com> wrote:
> Hi all! Some newbie questions again.
>
> class B {}
>
> class A {
> B* add();
> }
>
> method "add" of class A creates a new instance of class B and stores
> reference to it somewhere inside.
Class A is responcible for the deletion, right?
> I'm trying to expose it to python this way:
> ".def("add", &A::add, bp::return_value_policy<bp::manage_new_object>())"
If the answer to my question is "yes", that you should use
"return_internal_reference" call policy.
http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/return_internal_reference.html#return_internal_reference-spec
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list