2

現在、Boost::Python を使用して C++ インターフェイス (純粋な仮想クラス) を Python に公開しようとしています。C++ インターフェイスは次のとおりです。

エージェント.hpp

#include "Tab.hpp"
class Agent
{
    virtual void start(const Tab& t) = 0;
    virtual void stop() = 0;
};

そして、「公式」チュートリアルを読んで、次の Python ラッパーを作成してビルドすることができました。

エージェント.cpp

#include <boost/python.hpp>
#include <Tabl.hpp>
#include <Agent.hpp>
using namespace boost::python;

struct AgentWrapper: Agent, wrapper<Agent>
{
    public:
    void start(const Tab& t)
    {
        this->get_override("start")();
    }
    void stop()
    {
        this->get_override("stop")();
    }
};

BOOST_PYTHON_MODULE(PythonWrapper)
{
    class_<AgentWrapper, boost::noncopyable>("Agent")
        .def("start", pure_virtual(&Agent::start) )
        .def("stop", pure_virtual(&Agent::stop) )
    ;
}

ビルド中に問題がないことに注意してください。しかし、私が懸念しているのは、ご覧のとおり、AgentWrapper::start が Agent::start に引数を渡していないように見えることです。

void start(const Tab& t)
{
    this->get_override("start")();
}

Pythonラッパーは、「開始」が1つの引数を受け取ることをどのように認識しますか? どうすればそうできますか?

4

1 に答える 1

4

get_override 関数は、さまざまな数の引数に対する多数のオーバーロードを持つオーバーライドタイプのオブジェクトを返します。したがって、これを行うことができるはずです:

void start(const Tab& t)
{
    this->get_override("start")(t);
}

これを試しましたか?

于 2010-02-17T01:28:10.627 に答える