Craig Bosma wrote:
Hi,
I'm pretty new to Boost.Python, and am trying to wrap a simple class
similar to:
class Foo {
public:
float value() const { return value_; }
float& value() { return value_; }
private:
float value_;
};
I have no problem wrapping value() as a read-only property, like so:
class_<Foo>("Foo")
.add_property("value", (float (Foo::*)(void) const)&Foo::value)
;
But I'm having a difficult time determining how to wrap the
unconventional 'setter' method for read-write property access; as you
can see it returns a non-const reference to be set rather than taking
the new value as an argument. Any suggestions?
Use a thin wrapper function, such as:
void Foo_setter(Foo &foo, float v) { foo.value() = v;}
...
float (Foo::*getter)() const = &Foo::value; // to disambiguate
class_<Foo> foo("Foo");
foo.add_property("value", getter, Foo_setter);
HTH,
Stefan
...
class_<Foo>("Foo")
.add_property("value", Foo::value, setter);
should
Thanks,
Craig
------------------------------------------------------------------------
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
--
...ich hab' noch einen Koffer in Berlin...
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig