Ho alcune funzioni lambda che voglio associare usando boost :: bind o std :: bind. (Non importa quale, finché funziona.) Purtroppo entrambi mi danno diversi erros compilatore:Come utilizzare le funzioni lambda con boost :: bind/std :: bind in VC++ 2010?
auto f = [](){ cout<<"f()"<<endl; };
auto f2 = [](int x){ cout<<"f2() x="<<x<<endl; };
std::bind(f)(); //ok
std::bind(f2, 13)(); //error C2903: 'result' : symbol is neither a class template nor a function template
boost::bind(f)(); //error C2039: 'result_type' : is not a member of '`anonymous-namespace'::<lambda0>'
boost::bind(f2, 13)(); //error C2039: 'result_type' : is not a member of '`anonymous-namespace'::<lambda1>'
Quindi, qual è la soluzione più semplice per questo?
Perché si desidera utilizzare il bind? Non puoi semplicemente chiamare f() o f2 (1)? – Jagannath
@Jagannath: Questo era ovviamente solo un semplice esempio, ma in realtà voglio memorizzare il risultato del bind in un oggetto funzione. – Timo
Perché vuoi usare il bind? Pensavo che C++ 0x fornisse chiusure? –