On 2014-10-03 12:56, MM wrote: > 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?
Good question. The policy you want is likely pass-by-value (In Python strings are immutable anyhow), however I have no idea how to express that with the add_property() call. As a quick hack I suggest adding a wrapper function that returns the result by-value: std::string get_name(C &c) { return c.get_name();} and use that. That's neither elegant nor efficient (if you call it a lot), but it may unblock you until you find a real fix. Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig