List Info

Thread: interaction of boost::shared_ptr with boost::python




interaction of boost::shared_ptr with boost::python
country flaguser name
United States
2007-10-09 14:02:27
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>



_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )