std :: function成员函数 [英] std::function to member function

查看:785
本文介绍了std :: function成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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;
}



我在上述两个绑定函数中收到错误:

I am getting errors in both of the above bind functions:

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

语法错误在哪里?我使用visual studio 2010

Where is the syntax error? I am using visual studio 2010

推荐答案

Funcp func = std :: bind(& A :: func,& a,std :: placeholders :: _ 1,std :: placeholders :: _ 2);

这篇关于std :: function成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆