[C++-sig] interaction of boost::shared_ptr with boost::python
Neal Becker
ndbecker2 at gmail.com
Tue Oct 9 21:02:27 CEST 2007
A bit puzzled about this one.
struct X {
X() { std::cout << "X()" << '\n'; }
~X() { std::cout << "~X()" << '\n'; }
};
boost::shared_ptr<X> make_x () {
return boost::shared_ptr<X> (new X);
}
boost::shared_ptr<X> make_x_from_shared (boost::shared_ptr<X> x) {
return boost::shared_ptr<X> (new X);
}
X* clone1 (X const& x) {
return new X;
}
boost::shared_ptr<X> clone2 (X const& x) {
return boost::shared_ptr<X> (new X);
}
BOOST_PYTHON_MODULE (stuff) {
class_<X> ("X", no_init)
.def ("__init__", make_constructor (make_x))
.def ("__init__", make_constructor (make_x_from_shared))
.def ("__copy__", &clone1, return_value_policy<manage_new_object>())
.def ("__copy2__", &clone2)
;
def ("clone1", &clone1, return_value_policy<manage_new_object>());
def ("clone2", &clone2);
>>> x = X()
>>> clone2(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: No to_python (by-value) converter found for C++ type: boost::shared_ptr<X>
More information about the Cplusplus-sig
mailing list