Using bind1st for a method that takes argument by reference

后端 未结 4 1088
悲哀的现实
悲哀的现实 2020-12-01 20:59

I have a struct like this:

struct A {
    void i(int i) {}
    void s(string const &s) {}
};

Now when I try this:

bind         


        
4条回答
  •  被撕碎了的回忆
    2020-12-01 21:30

    Change references by pointers

    #include 
    #include 
    
    struct A {
        void i(int i) {}
        void s(const std::string *s) {}
    };
    
    
    int main(void)
    {
        A a;
        std::bind1st(std::mem_fun(&A::i), &a)(0);
        const std::string s("");
        std::bind1st(std::mem_fun(&A::s), &a)(&s);
    }
    

提交回复
热议问题