Problem with smart pointers

swell at netcourrier.com swell at netcourrier.com
Sat Feb 11 08:11:16 EST 2006


Hello,
    I use the Boost.Python lib for a couple of weeks now and i am
facing a pb.
To sum up i have a small hierarchy of objects and have a factory to
build concrete object. The pb is i think aroud the auto_ptr object that
is not correctly managed by my code ( i use version 1.33 )
I think that the solution is obvious but i can't sort it out. If you
could have a look at this small test


struct X
{
 virtual int fun1() = 0;
 int fun2() { return 2;}
 virtual int fun3() { return -1; }
};

struct Y : public X
{
 int fun1() {return 1;}
 virtual fun3() { return 3; }
};

struct FactY
{
 static std:auto_ptr<X> create() { return std:auto_ptr<X>(new Y());}
};


BOOST_PYTHON_MODULE(hello)
{
 class_<X,  boost::noncopyable >("X",no_init);
 class_<Y,  boost::python::bases<X> >("Y")
  .def("fun1",&Y::fun1)
  .def("fun2",&Y::fun2)
  .def("fun3",&Y::fun3)
 ;

 class_<FactY>("FactY",no_init)
  .def("create",&FactY::create)
  .staticmethod("create")
 ;
}
 
Many Thx




More information about the Python-list mailing list