boost python を使用して多重継承に純粋仮想関数を使用する方法。私が得たエラーは、「Derived1」が抽象クラスをインスタンス化できないということです。「Derived2」は抽象クラスをインスタンス化できません。このコードは、派生クラスが 1 つしかなく、複数の派生クラスが機能しない場合に機能します。手伝ってくれてありがとう。
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)
;
}