[C++-sig] class properties for functions returning references

anirudh vij anirudhvij at gmail.com
Thu Nov 27 14:53:43 CET 2008


Hi,

I've been trying to make the following code work

*class Bar{
public:
    Bar():_int(4){};
    ~Bar(){};
    int get()
    {return _int;}
private:
    int _int;
};

class Foo
{
public:
    Foo():_bar(Bar()){};
    ~Foo(){};
    Bar& get_bar(){return _bar;}
private:
    Bar _bar;
};

#include <boost/python.hpp>

BOOST_PYTHON_MODULE(test)
{
    using namespace boost::python;
    class_<Bar>("Bar")
    .def("get",&Bar::get)
;
    class_<Foo>("Foo")
      .add_property("bar",
make_getter(&Foo::get_bar,return_value_policy<copy_non_const_reference>())
)
    ;
}*

The idea is to expose the _bar member via the get() function. I dont want to
use def_readonly (since this is a dummy test case for a more general problem
I am facing of using getters with functons returning references)

I get a compile error, with the source of the error in the return value
policy . The error log is attached.

I also tried return_internal_reference<>(), and
return_value_policy<return_by_value>, but both give compilation errors.

Any help is appreciated

regards,
anirudh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081127/f480b332/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compile_log
Type: application/octet-stream
Size: 10236 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081127/f480b332/attachment.obj>


More information about the Cplusplus-sig mailing list