Boost Python - 不构建的抽象基类

时间:2017-01-09 17:57:36

标签: python c++ boost

我有一个带有纯虚拟的基类(StandardObserver),所以我将它包装起来,以便我可以在Python中创建实例并在它们上面回调,但它不会构建。我需要公开基类,因为我需要以多态方式传递dervied类,但我还需要包装类,因为OnMessage是纯虚拟回调。

class Subscription::StandardObserver : public Subscription::Observer::Impl
{
public:
    typedef implementation::ObjectReference<StandardObserver> Ptr;
    class Context : public Observer::Context
    {
    public:
        Context(const Subscription& subscription, const Message& message, const Criteria& criteria) : Observer::Context(subscription, message, criteria) {}
    };

    virtual void OnMessage(const Context& context) = 0;
};

struct PyStandardObserver : public Subscription::StandardObserver, public wrapper<Subscription::StandardObserver>
{
     void OnMessage(const Subscription::StandardObserver::Context& context)
     {
          if (override f = this->get_override("OnMessage"))
                f(context);
     }
};

boost :: python

class_<Subscription::StandardObserver, boost::noncopyable >("SO", boost::python::no_init);

class_<Subscription::StandardObserver::Context>("Context", no_init);

class_<PyStandardObserver, bases<Subscription::StandardObserver>>("StandardObserver")
    .def("OnMessage", &PyStandardObserver::OnMessage);

错误:

 Error  4   error C2259: 'eapi::Subscription::StandardObserver' : cannot instantiate abstract class

0 个答案:

没有答案