[C++-sig] method chaining in noncopyable derived class
Buras, Brian
brian.buras at verigy.com
Wed Apr 8 18:06:39 CEST 2009
I'm trying to wrap an API that uses method chaining (methods that return reference to same object) and restricts assignment/copy. Is there a reason I can't use return_internal_reference?
# want to be able to do this in Python
d = myexample.Derived("name")
d.setSomething(500).execute()
But I get a segfault at return of setSomething()
If I separate the 2 method calls it works.
Here is the API and boost::python wrapper:
enum MODES {A,B};
class Base {
public:
Base(const string& p);
virtual ~Base();
void execute(MODES mode = A);
private:
string pn;
Base& operator=(const Base& rhs);
Base(const Base&);
};
class Derived : public Base {
public:
Derived(const string& p);
virtual ~Derived();
Derived& setSomething(int a);
private:
int aa;
};
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(d_o,execute,0,1)
BOOST_PYTHON_MODULE(myexample) {
class_<Base,boost::noncopyable>("Base",no_init);
class_<Derived, bases<Base>,boost::noncopyable >("Derived",init<string>())
.def("execute",&Derived::execute,d_o())
.def("setSomething",&Derived::setSomething, return_internal_reference<>())
//.def("setSomething",&Derived::setSomething, return_value_policy<reference_existing_object>())
//.def("setSomething",&Derived::setSomething, return_value_policy<copy_non_const_reference>());
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090408/192f5662/attachment.htm>
More information about the Cplusplus-sig
mailing list