c++ - std::function 到成员函数

标签 c++ function-pointers

#include <functional>

struct A
{
    int func(int x, int y)
    {
        return x+y;
    }
};

int main()
{

    typedef std::function<int(int, int) > Funcp;
    A a;
    //Funcp func = std:::bind(&A::func, &a);
    Funcp func = std::bind(&A::func, a, std::placeholders::_1);


    return 0;
}

我在上述两个绑定(bind)函数中都遇到了错误:

 error C2825: '_Fty': must be a class or namespace when followed by '::'

语法错误在哪里?我正在使用 Visual Studio 2010

最佳答案

Funcp func = 
    std::bind(&A::func, &a, std::placeholders::_1, std::placeholders::_2);

关于c++ - std::function 到成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154116/

相关文章:

c++ - ZeroMQ 始终发送和获取 1 个字节(使用 cppzmq 绑定(bind))

c++ - OpenCV中数据库视频匹配的实现帮助

c++ - libarb.so : cannot open shared object file: No such file or directory

不同类之间非静态函数的C++回调

c - 对变量和指针使用相同的名称两次(c 编程)

C++ - 绕过 WinSock Hook

c++ - 跨 DLL/共享库使用命名空间

c++ - 提取函数参数类型作为参数包

c++ - 传递重载函数指针及其参数时的错误类型推导

c++ - 非捕获 lambda 和函数指针作为重载函数歧义中的参数