Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

c++ - std::function to member 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 '::'

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...