0

コンパイル時にエラーが発生しますが、その理由がわかりません。次のコードはコンパイルを拒否し、次のエラーが発生します。

エラー C2664: 'void (PyObject *,const char *,boost::type *)': パラメーター 1 を 'const char *' から 'PyObject *' に変換できません
エラー C2664: 'void (PyObject *,const char *,boost ::type *)': パラメーター 3 を 'boost::shared_ptr' から 'boost::type *' に変換できません

PyObject* self = ...;
const char* fname = "...";
boost::function<void (boost::shared_ptr<Event>)> func;
func = boost::bind(boost::python::call_method<void>, self, fname, _1);
4

1 に答える 1

1

boost::python::call_method次のように定義された、異なる数の引数を取るいくつかのオーバーロードされた関数で構成されます。

template <class R>
R call_method(PyObject* self, char const* method);
template <class R, class A1>
R call_method(PyObject* self, char const* method, A1 const&);
template <class R, class A1, class A2>
R call_method(PyObject* self, char const* method, A1 const&, A2 const&);
...

直接呼び出すと (例: call_method<void>(self, name, arg1, arg2))、コンパイラは正しいオーバーロードとテンプレート化された引数の型を自動的に選択できます。ただし、関数ポインターをに渡すときはcall_methodbind次を使用して、オーバーロードと引数の型を手動で指定する必要があります。

call_method<ReturnType, Arg1Type, Arg2Type, ...>

またはこの場合:

call_method<void, boost::shared_ptr<Event> >
于 2011-08-03T14:34:57.817 に答える