use std::bind with overloaded functions

前端 未结 1 1829
日久生厌
日久生厌 2020-12-18 00:36

I cannot find out how to bind a parameter to an overloaded function using std::bind. Somehow std::bind cannot deduce the overloaded type (for its t

相关标签:
1条回答
  • 2020-12-18 01:11

    You may use:

    auto f_binder = std::bind(static_cast<double(&)(double)>(f), 2.);
    

    or

    auto f_binder = bind<double(double)>(f, 2.);
    

    Alternatively, lambda can be used:

    auto f_binder = []() {
        return f(2.);     // overload `double f(double)` is chosen as 2. is a double.
    
    };
    
    0 讨论(0)
提交回复
热议问题