2011-08-31 12 views

risposta

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

E come utilizzare tale funzione? Non dovremmo chiamarlo come 'proxy_do_stuff (...)'? – Rella

+0

Ho aggiunto come usarlo. Non c'è bisogno di bla-bla-bla. –

4

Il tipo di ritorno di boost :: bind è di tipo boost :: function. Vedi sotto:

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

+1 Il tipo restituito è in realtà boost :: _ bi :: bind_t , boost :: _ bi :: list3 , boost :: _ bi :: value , boost :: _ bi :: value >> ma lo stai convertendo in boost :: funzione

Problemi correlati