[C++-sig] Re: class_<>::add_property() on CVS-HEAD
David Abrahams
dave at boost-consulting.com
Tue Dec 30 16:26:18 CET 2003
Jonathan Brandmeyer <jbrandmeyer at earthlink.net> writes:
> Is there a replacement for this functionality?
>
> Thanks,
> Jonathan Brandmeyer
>
> --------------------------------------------------------------
> #include <boost/python.hpp>
>
> namespace test {
>
> // Hmm. return_internal_reference<>() wants to wrap a real class.
> class ret_type
> {
> public:
> double i;
> };
>
> class crash_me
> {
> private:
> ret_type i;
> public:
> ret_type& get_i() { return i; }
> };
>
> }
>
> BOOST_PYTHON_MODULE( crash_test)
> {
> using namespace boost::python;
>
> class_< test::ret_type>( "ret_type")
> .def_readwrite( "i", &test::ret_type::i)
> ;
>
> class_< test::crash_me> crash_me_wrapper( "crash_me");
>
> crash_me_wrapper
> .def( "get_i", &test::crash_me::get_i , return_internal_reference<>())
> ;
>
> // The following works under Boost 1.30, but not CVS-HEAD
> // (sourceforge repository).
> crash_me_wrapper.add_property( "i", crash_me_wrapper.attr("get_i"));
> }
Jonathan,
Sorry it took so long to respond; I'll fix it in CVS momentarily.
In the meantime, you can use:
crash_me_wrapper.add_property(
"i", object(crash_me_wrapper.attr("get_i"))
);
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list