[C++-sig] How to override a property setter?
ilias
ilias at thechampion.ru
Thu Dec 18 12:21:02 CET 2014
I got a class:
class X
{
private:
std::wstring text_;
public:
std::wstring text() const { return text_; }
void set_text(const std::string& text) { text_ = from_utf8(text); }
void set_text(const std::wstring& text) { text_ = text; }
};
I'm trying to use it as a property:
BOOST_PYTHON_MODULE(test)
{
class_<X>("X")
.add_property("text", &X::text, <what here?>)
;
}
What should I write to get following behavior:
>>> x = X()
>>> x.text = "abc" # I want X::set_text(const std::string&) to be invoked here
>>> x.text = u"abc" # Here I expect X::set_text(const std::wstring&) to be
called
--
Ilya.
More information about the Cplusplus-sig
mailing list