相关疑难解决方法(0)

将std :: bind与重载函数一起使用

我无法找到如何使用参数将参数绑定到重载函数std::bind.不知何故std::bind不能推断出重载类型(对于它的模板参数).如果我不重载该功能一切正常.代码如下:

#include <iostream>
#include <functional>
#include <cmath>

using namespace std;
using namespace std::placeholders;

double f(double x) 
{
    return x;
}

// std::bind works if this overloaded is commented out
float f(float x) 
{
    return x;
}

// want to bind to `f(2)`, for the double(double) version

int main()
{

    // none of the lines below compile:

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

    // auto f_binder = bind((std::function<double(double)>)f, \
    //  static_cast<double>(2));

    // auto f_binder = bind<std::function<double(double)>>(f, \ …
Run Code Online (Sandbox Code Playgroud)

c++ overloading stdbind c++11

7
推荐指数
1
解决办法
3772
查看次数

标签 统计

c++ ×1

c++11 ×1

overloading ×1

stdbind ×1