[C++-sig] Policies again

Piotr Jaroszynski p.jaroszynski at gmail.com
Thu May 3 16:30:07 CEST 2007


On Wednesday 02 of May 2007 22:56:51 Piotr Jaroszynski wrote:
> Let me show you my current problem:
To be even more precise:

#include <boost/python.hpp>
namespace bp = boost::python;

struct Blah;

struct Foo {
    Blah * b;
    Foo(Blah * blah) : b(blah) { }
};

struct Blah_f {
    Foo * f;
    Blah_f(Blah * blah) : f(new Foo(blah)) { }
};

struct Blah : Blah_f {
    Blah() : Blah_f(this) { }
};

BOOST_PYTHON_MODULE(policies)
{
    bp::register_ptr_to_python<Foo*>();
    bp::class_<Foo, boost::noncopyable> f("Foo", bp::no_init);
    bp::class_<Blah> b("Blah");
    b.add_property("f", bp::make_getter(&Blah::f,
	 bp::return_internal_reference<>()));
}

You will probably ask where is the big difference... So when using the 
return_internal_reference policy, which is probably wrong anyway, I get:
Traceback (most recent call last):
  File "./test.py", line 5, in ?
    print Blah().f
Boost.Python.ArgumentError: Python argument types in
    None.None(Blah)
did not match C++ signature:
    None(Blah_f {lvalue})

I think I should use one of the with_custodian_and_ward variations, but I 
couldn't make any of them to even compile.

-- 
Best Regards,
Piotr Jaroszynski



More information about the Cplusplus-sig mailing list