[C++-sig] returning reference to enum
Emmanuel Taurel
etaurel at cells.es
Tue Nov 22 12:31:37 CET 2005
Hello everybody,
I have a very simple example where I try to wrap a C++ class. In this class
there is a method which returns a reference to an internal variable which is
an enumeration. I try to wrap this method with the return_internal_reference
Call Policy but I have a compiler error.
First here is my little C++ file
----------------------------------------------------------------------------
------------
#include <boost/python.hpp>
using namespace boost::python;
enum DispLevel
{
OPERATOR = 0,
EXPERT
};
class MyClass
{
public:
MyClass() {}
~MyClass() {}
void set_enum(DispLevel dl) {disp=dl;}
DispLevel &get_enum() {return disp;}
protected:
DispLevel disp;
};
BOOST_PYTHON_MODULE(PyTangoDs)
{
enum_<DispLevel>("DispLevel")
.value("OPERATOR",OPERATOR)
.value("EXPERT",EXPERT)
;
class_<MyClass>("MyClass")
.def("set_enum",&MyClass::set_enum)
.def("get_enum",&MyClass::get_enum,return_internal_reference<>())
;
}
The error I get from the compiler is :
----------------------------------------------------------------------------
---------------------------------------------------------
gcc-C++-action bin/enum/PyTangoDs.so/gcc/debug/shared-linkable-true/py_ds.o
/home/etaurel/src/boost_1_33_0/boost/python/object/make_instance.hpp: In
static
member function `static PyObject*
boost::python::objects::make_instance_impl<T, Holder,
Derived>::execute(Arg&) [with Arg = DispLevel*, T = DispLevel, Holder =
boost::python::objects::pointer_holder<DispLevel*, DispLevel>, Derived =
boost::python::objects::make_ptr_instance<DispLevel,
boost::python::objects::pointer_holder<DispLevel*, DispLevel> >]':
/home/etaurel/src/boost_1_33_0/boost/python/to_python_indirect.hpp:96:
instantiated from `static PyObject*
boost::python::detail::make_reference_holder::execute(T*) [with T =
DispLevel]'
/home/etaurel/src/boost_1_33_0/boost/python/to_python_indirect.hpp:60:
instantiated from `PyObject* boost::python::to_python_indirect<T,
MakeHolder>::execute(const U&, mpl_::bool_<false>) const [with U =
DispLevel, T = DispLevel&, MakeHolder =
boost::python::detail::make_reference_holder]'
/home/etaurel/src/boost_1_33_0/boost/python/to_python_indirect.hpp:37:
instantiated from `PyObject* boost::python::to_python_indirect<T,
MakeHolder>::operator()(const U&) const [with U = DispLevel, T = DispLevel&,
MakeHolder = boost::python::detail::make_reference_holder]'
/home/etaurel/src/boost_1_33_0/boost/python/detail/invoke.hpp:88:
instantiated from `PyObject*
boost::python::detail::invoke(boost::python::detail::invoke_tag_<false,
true>, const RC&, F&, TC&) [with RC =
boost::python::to_python_indirect<DispLevel&,
boost::python::detail::make_reference_holder>, F = DispLevel&(MyClass::*)(),
TC = boost::python::arg_from_python<MyClass&>]'
/home/etaurel/src/boost_1_33_0/boost/python/detail/caller.hpp:199:
instantiated from `PyObject* boost::python::detail::caller_arity<1>::impl<F,
Policies, Sig>::operator()(PyObject*, PyObject*) [with F =
DispLevel&(MyClass::*)(), Policies =
boost::python::return_internal_reference<1,
boost::python::default_call_policies>, Sig = boost::mpl::vector2<DispLevel&,
MyClass&>]'
/home/etaurel/src/boost_1_33_0/boost/python/object/py_function.hpp:38:
instantiated from `PyObject*
boost::python::objects::caller_py_function_impl<Caller>::operator()(PyObject
*, PyObject*) [with Caller =
boost::python::detail::caller<DispLevel&(MyClass::*)(),
boost::python::return_internal_reference<1,
boost::python::default_call_policies>, boost::mpl::vector2<DispLevel&,
MyClass&> >]'
/home/etaurel/src/boost_1_33_0/boost/detail/call_traits.hpp:83:
instantiated from here
/home/etaurel/src/boost_1_33_0/boost/python/object/make_instance.hpp:24:
error: incomplete
type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member
`value'
----------------------------------------------------------------------------
-----------------------------------------------------------
Any idea welcome. Thank's very much in advance
Emmanuel Taurel (etaurel at cells.es)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20051122/2e383d6e/attachment.htm>
More information about the Cplusplus-sig
mailing list