yes i did that. class C { > public: > const std::string& get_name() const; > void set_name(const std::string&); > private: > std::string name_; > }; >
> class_<C>("C"). > .add_property("name", &C::get_name, &C::set_name); this fails to compile because of unspecified call policies about the string refs. The following, on the other hand, compiles. > class C { > public: > const std::string get_name() const; > void set_name(const std::string); > .... > class_<C>("C"). > .add_property("name", &C::get_name, &C::set_name); Which policy do I specify? and how do I set it in add_property? MM On 3 October 2014 17:50, Stefan Seefeld <ste...@seefeld.name> wrote: > On 2014-10-02 16:09, MM wrote: > > Hi > > > > class C { > > public: > > const std::string& name() const; > > std::string& name(); > > private: > > std::string name_; > > }; > > > > given this class C, how would I expose it to python with the class > > property name? > > > > class_<C>("C"). > > .add_property("name", &C::name, &C::name); > > > > or do I use 2 mem function pointers to distinguish the 2 names, and > > pass those 2 pointers? > > You need to disambiguate the two overloads. The cleanest way to do that > is to introduce two (local) variables of the appropriate > pointer-to-member-function types, then pass those variables to the > 'add_property' call. > In addition, I believe boost.python expects a different signature for > the setter (a function taking a value-type argument), so you may have to > provide a wrapper function for that, unless you want to modify the 'C' > class in-place. > > HTH, > Stefan > > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig >
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig