I am using boost::python to expose a C++ API into Python. Here is what I
am trying to do:
#include
#include <memory>
struct Subscriber {
virtual ~Subscriber() = 0;
static std::unique_ptr<Subscriber> create();
};
template<class T>
inline T* get_pointer(std::unique_ptr<T> const& p) {
return p.get();
}
BOOST_PYTHON_MODULE(subscriber) {
// Expose the class.
boost::python::class_<
Subscriber
, std::unique_ptr<Subscriber>
, boost::noncopyable
>("Subscriber");
// Expose its factory function.
bp::def("createSubscriber", Subscriber::create);
}
boost::python::class_<> constructor invocation spits out errors (full
compiler log attached):
/usr/local/ots/boost-1.51.0/include/boost/python/converter/as_to_python_function.hpp:40:75:
error: use of deleted function ‘std::unique_ptr<_Tp,
_Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp =
Subscriber; _Dp = std::default_delete<Subscriber>; std::unique_ptr<_Tp,
_Dp> = std::unique_ptr<Subscriber>]’
/usr/local/ots/boost-1.51.0/include/boost/python/object/pointer_holder.hpp:194:14:
error: cannot allocate an object of abstract type ‘Subscriber’
How do I make boost::python friendly to std::unique_ptr<> and how do I
wrap an abstract class please?
-- Maxim