Please refer the following code snippet. I want to use the std::bind
for overloaded function foobar
. It calls only the method with no arguments.
You need to use placeholders
for the unbound arguments:
auto a2 = std::bind(static_cast<void(Client::*)(int)>(&Client::foobar), cl,
std::placeholders::_1);
a2(5);
You can also perform the binding with a lambda capture (note that this is binds cl
by reference, not by value):
auto a2 = [&](int i) { cl.foobar(i); };