如何使用 boost python 将纯虚函数用于多重继承。我得到的错误是“Derived1”不能实例化抽象类。并且“Derived2”无法实例化抽象类。如果只有一个派生类但多个派生类不起作用,则此代码有效。感谢帮助。
class Base
{
public:
virtual int test1(int a,int b) = 0;
virtual int test2 (int c, int d) = 0;
virtual ~Base() {}
};
class Derived1
: public Base
{
public:
int test1(int a, int b) { return a+b; }
};
class Derived2
: public Base
{
public:
int test2(int c, int d) { return c+d; }
};
struct BaseWrap
: Base, python::wrapper<Base>
{
int test1(int a , int b)
{
return this->get_override("test")(a, b);
}
int test2(int c ,int d)
{
return this->get_override("test")(c, d);
}
};
BOOST_PYTHON_MODULE(example)
{
python::class_<BaseWrap, boost::noncopyable>("Base")
.def("test1", python::pure_virtual(&BaseWrap::test1))
.def("test2", python::pure_virtual(&BaseWrap::test2))
;
python::class_<Derived1, python::bases<Base> >("Derived1")
.def("test1", &Derived1::test1)
;
python::class_<Derived2, python::bases<Base> >("Derived2")
.def("test2", &Derived2::test2)
;
}