[C++-sig] class_<>::add_property() on CVS-HEAD

Jonathan Brandmeyer jbrandmeyer at earthlink.net
Wed Oct 29 04:17:59 CET 2003


The following example demonstrates a method of using add_property that
works with Boost.Python 1.30 but not CVS-HEAD (from sourceforge CVS). 
The example posted is somewhat useless as-is, but demonstrates something
that I started using for properties with non-trivial accessors.

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"));
}

--------------------------------------------------------
Testing with G++ 3.3.2 (Debian) results in the following error using
CVS-HEAD:

/home/jonathan/src/boost-CVS-HEAD/boost/boost/python/class.hpp: In
member
   function `boost::python::api::object boost::python::class_<T, X1, X2,
   X3>::make_fn(const F&) [with F =
   boost::python::api::proxy<boost::python::api::attribute_policies>, T
=
   test::crash_me, X1 = boost::python::detail::not_specified, X2 =
   boost::python::detail::not_specified, X3 =
   boost::python::detail::not_specified]':
/home/jonathan/src/boost-CVS-HEAD/boost/boost/python/class.hpp:365:  
instantiated from `boost::python::class_<T, X1, X2, X3>&
boost::python::class_<T, X1, X2, X3>::add_property(const char*, Get)
[with Get =
boost::python::api::proxy<boost::python::api::attribute_policies>, T =
test::crash_me, X1 = boost::python::detail::not_specified, X2 =
boost::python::detail::not_specified, X3 =
boost::python::detail::not_specified]'
crashme.cpp:38:   instantiated from here
/home/jonathan/src/boost-CVS-HEAD/boost/boost/python/class.hpp:429:
error: no
   matching function for call to `get_signature(const
   boost::python::api::proxy<boost::python::api::attribute_policies>&,
   test::crash_me*)'





More information about the Cplusplus-sig mailing list