[C++-sig] Re : How to wrap this overloaded member function whose return type is reference ?

David Abrahams dave at boost-consulting.com
Sat Feb 22 18:42:22 CET 2003


"horace\(seednet\)" <horace_hdsl at seed.net.tw> writes:

> Dave Abrahams wrote :
>
>> Can you post the error message(s) you get?  That would be a nice start.
>
> Ok, Dave, If you want to see those error messages, here you go. Last
> time I thought it wasn't too polite to dump those lengthy error
> messages here.

The ones you've got below aren't too lengthy ;-)

> for this line of code :
>
>   .def_readonly("origin",&point3d::origin)
>
> I got 
>
> D:\test\point3d.cpp(6) : error C2784: 'class
> boost::python::class_<class point3d,struct
> boost::python::detail::not_specified,struct
> boost::python::detail::not_specified,struct
> boost::python::detail::not_specified> &__thiscall
> boost::python::class_<class point3d,struct
> boost::python::detail::not_specified,struct
> boost::python::detail::not_specified,struct
> boost::python::detail::not_specified>::def_readonly(const char *,
> point3d::*)' : could not deduce template argument for ' point3d::*'
> from 'const class point3d *'

OK, the problem here is that point3d::origin is not a regular data
member.  A static data member acts just like an ordinary variable, so
the type of &point3d::origin is not

    point3d const point3d::*

but

    point3d const*

I don't have a way of enabling you to restrict modification, but one
easy way to deal with this is:

    object class_point3d
      = class_<point3d>("point3d")
         .def(init<>())    // compiles ok
         .def(init<const point3d&>() // compiles ok
         .def(init<double,double,double>(args("x", "y", "z")))
         ...
         ;

    class_point3d.attr("origin") = point3d::origin;


> for this line of code  :
>
>   .def("set",(point3d& (point3d::*)(double, double, double)) point3d::set,args("x", "y", "z")) 
>
> I got 
>
> d:\boost_1_29_0\boost/python/detail/returning.hpp(175) : error
> C2079: 'cr' uses undefined struct
> 'specify_a_result_policy_to_wrap_functions_returning<class point3d &>'
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That should be a big clue.  Have you read about CallPolicies?

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/python/doc/tutorial/doc/call_policies.html

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/python/doc/v2/CallPolicies.html#CallPolicies-concept

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/python/doc/v2/reference.html#models_of_call_policies

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/python/doc/v2/reference.html#result_converter_generators

> I think my problem in using Boost.Python is that I don't know what I'm doing.  

Possibly; If so I hope that my reply will help to correct that.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list