std::function to member function

这一生的挚爱 提交于 2019-12-17 16:42:07

问题


#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 '::'

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


回答1:


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



来源:https://stackoverflow.com/questions/5154116/stdfunction-to-member-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!