std::bind and overloaded function

后端 未结 1 2004
终归单人心
终归单人心 2021-02-19 05:03

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.

<
1条回答
  •  温柔的废话
    2021-02-19 05:41

    You need to use placeholders for the unbound arguments:

    auto a2 = std::bind(static_cast(&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); };
    

    0 讨论(0)
提交回复
热议问题