如何使用 boost python 在派生类中调用纯虚函数。我得到的错误是无法实例化抽象基类。示例代码如下:
class Base
{
public:
virtual int test() = 0;
};
class Derived : public Base
{
public:
int test()
{
int a = 10;
return a;
}
};
struct BaseWrap : Base, wrapper<Base>
{
Int test()
{
return this->get_override(“test”)();
}
};
BOOST_PYTHON_MODULE(Pure_Virtual)
{
Class_<BaseWrap, boost::noncopyable>(“Base”, no_init)
.def(“test”, pure_virtual($Base::test)
;
Class_<Derived, bases<Base> >(“Derived”)
.def(“test”, &Derived::test)
;
}