vendredi 23 février 2018

Std bind equivalent to lambda for binding a member function to a std function

I can bind a private member function using a lambda. I'm struggling to write the equivalent using std::bind. This is my attempt, but it doesn't compile.

#include <functional>

class A { 
    private: 
        double foo(double x, double y); 
    public:          
        A(); 
        std::function<double(double,double)> std_function;      
 }; 

A::A() {
    // This works:
    //std_function = [this](double x, double y){return foo(x,y);};

    std_function = std::bind(&A::foo,this,std::placeholders::_1));
} 

Aucun commentaire:

Enregistrer un commentaire