Using bind1st for a method that takes argument by reference

后端 未结 4 1074
悲哀的现实
悲哀的现实 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:47

    std::bind1st and std::bind2nd don't accept functors which take reference arguments, because they themselves form references to these arguments. You can

    1. use pointers for your function inputs instead of references
    2. use boost::bind
    3. accept the performance cost of copying the string

提交回复
热议问题