다음 코드 단편을 참조하십시오. 오버로드 된 기능 foobar
에 std::bind
을 사용하고 싶습니다. 인수가없는 메소드 만 호출합니다.std :: bind 및 오버로드 된 함수
auto a2 = std::bind(static_cast<void(Client::*)(int)>(&Client::foobar), cl,
std::placeholders::_1);
a2(5);
또한 (값이 아닌 참조에 의해 결합이 떨어져 있음을 알아 cl
을)를 람다 캡처 바인딩을 수행 할 수 있습니다 :
#include <functional>
#include <iostream>
class Client
{
public :
void foobar(){std::cout << "no argument" << std::endl;}
void foobar(int){std::cout << "int argument" << std::endl;}
void foobar(double){std::cout << "double argument" << std::endl;}
};
int main()
{
Client cl;
//! This works
auto a1 = std::bind(static_cast<void(Client::*)(void)>(&Client::foobar),cl);
a1();
//! This does not
auto a2= [&](int)
{
std::bind(static_cast<void(Client::*)(int)>(&Client::foobar),cl);
};
a2(5);
return 0;
}
람다에 '돌아 가기'가 없습니다. – ildjarn