2011-08-31 15 views

cevap

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

Ve bu işlev nasıl kullanılır? Proxy_do_stuff (...) 'olarak adlandırmamalı mıyız? – Rella

+0

Nasıl kullanacağım bölümünü ekledim. Bla-bla-bla'ya gerek yok. –

4

Destek türünün dönüş türü :: bağlama türünde boost :: işlevidir. Aşağıya bakın:

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

+1 Dönüş türü aslında desteklenmektedir :: _ bi :: bind_t , boost :: _ bi :: liste3 , boost :: _ bi :: değeri , boost :: _ bi :: değeri >> ancak bir yükseltmeye dönüştürüyorsanız :: işlev

İlgili konular