2011-08-31 6 views
5

だから私はのような関数を作成したい:boost :: bindの結果となる引数を持つ関数を作成するには?

void proxy_do_stuff(boost::bind return_here) 
{ 
    return_here(); // call stuff pased into boost::bind 
} 

そして、私は好き、それを呼び出すことができます。そのようなことをやって

proxy_do_stuff(boost::bind(&myclass::myfunction, this, my_function_argument_value, etc_fun_argument)); 

どのように?

答えて

3
#include <boost/bind.hpp> 

template<typename T> 
void proxy_do_stuff(T return_here) 
{ 
    return_here(); // call stuff pased into boost::bind 
} 

struct myclass 
{ 
    void myfunction(int, int) 
    { 
    } 
    void foo() 
    { 
     int my_function_argument_value = 3; 
     int etc_fun_argument= 5; 
     proxy_do_stuff(boost::bind(&myclass::myfunction, this, my_function_argument_value, etc_fun_argument)); 
    } 
}; 

int main() 
{ 
    myclass c; 
    c.foo(); 
    return 0; 
} 
+0

このような機能の使い方は? 'proxy_do_stuff (...)'のように呼び出すべきではありませんか? – Rella

+0

使い方を追加しました。 bla-bla-blaの必要はありません。 –

4

boost :: bindの戻り値の型はboost :: functionの型です。下記を参照してください:

void proxy_do_stuff(boost::function<void()> return_here) 
{ 
    return_here(); // call stuff pased into boost::bind 
} 
+3

+1戻り値の型は実際にはboost :: _ bi :: bind_t 、boost :: _ bi :: list3 、boost :: _ bi :: value 、boost :: _ bi :: value >ですが、boost :: functionに変換しています

関連する問題