-1

I try to bind a class member function with param as rval to boost::function. But it doesn't work. my sample false code :

class Class1
{
    int Foo1(int&& b)
    {
        return b;
    }   

    void foo2()
    {
        boost::function<int(int&&)> fc(boost::bind(&Class1::Foo1, this, _1) 
    }   
};
庄嘉琪
  • 21
  • 2
  • 1
    *How* doesn't it work? Please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask), learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve), and also read [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Aug 03 '18 at 08:55
  • Also read all of http://idownvotedbecau.se/ to learn some reasons your question might be down-voted. For example http://idownvotedbecau.se/beingunresponsive. – Some programmer dude Aug 03 '18 at 10:11
  • It is difficult to offer solutions when the problem statement is simply, ["it doesn't work"](http://idownvotedbecau.se/itsnotworking/). Please [edit] your question to give a more complete description of what you expected to happen and how that differs from the actual results. See [ask] for hints on what makes a good explanation. – Toby Speight Aug 03 '18 at 10:37

1 Answers1

1

Use a lambda expression:

boost::function<int(int&&)> fc = [this](int&& x)
{
    return Foo1(x);
};
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416