2011-08-03 10 views
0

コンパイル時にエラーが発生し、その理由を理解できません。機能とPythonを使ったBoost.Bind

エラーC2664: '無効(PyObject *、constのchar型の*は、後押し::タイプ*)':のconst char型「からパラメータ1を変換することはできません*を次のコードは、私に次のエラーを与えて、コンパイルすることを拒否します'to' PyObject * '
' 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); 

答えて

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_method<ReturnType, Arg1Type, Arg2Type, ...> 

するか、この場合は:あなたはbindcall_methodに関数ポインタを渡すときには、手動で使用することにより、過負荷および引数の型を指定する必要が

call_method<void, boost::shared_ptr<Event> > 
関連する問題