Как правильно передать функцию и переменные?
Пытаюсь передать функцию print из класса А
class A{
public:
void print(int i, std::string& str){};
};
передаю функцию
std::bind( std::reference_wrapper<void(int, std::string&)> (&A::print), this,std::placeholders::_1, std::placeholders::_2)
принимаю в другой функции
std::function<void(int i, std::string& str) > func
как исправить?
Ответы (1 шт):
Автор решения: Rivand
→ Ссылка
class A {
public:
void print( int i, std::string& str ) { cout << str << std::endl; };
};
void Foo( std::function<void( int, std::string&)> func ) {
std::string str ( "Hello world!" );
func( 0, str );
}
int main() {
A a_object;
Foo(std::bind(&A::print, &a_object, std::placeholders::_1, std::placeholders::_2));
return 0;
}