[C++-sig] [boost::python] Unresolved overloaded function - methods with same name
Roman Yakovenko
roman.yakovenko at gmail.com
Fri Oct 27 19:49:40 CEST 2006
On 10/27/06, yardbird <yardbird at nerdshack.com> wrote:
> Hello,
>
> I have a problem with getters/setters methods with the same name which both
> return cont/non-const reference to a class' data member. For instance:
>
> struct Foo {
> Foo(int x) { b = x; }
> int const& get_b() const { return b; }
> int & get_b() { return b; }
> private:
> int b;
> };
>
> // Wrapper code
>
> BOOST_PYTHON_MODULE(my_module)
> {
> class_<Foo>("Foo", init<int>())
> .def("get_b", &Foo::get_b);
-----------------------^^^^^^^^^^^
typedef int const& (Foo::*get_b_const_type) const;
.def( "get_b", get_b_const_type( &Foo::get_b ) );
The idea is to use function type to specify to compiler what function
you want to export.
I think you also will have to specify call policies:
return_value_policy< copy_const_reference >
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list