-1

I would like to call a method after another method using std::function. Suppose i have something like this

class foo
{

   std::function<void(int)> fptr;

   void bar(int){
   }
   void rock(){
   }
public:

   foo() {
       fptr = bind(&foo::bar,this,std::place_holder::_1); //<------Statement  1
   }
}

Now because of statement 1 if i call fptr(12) the method bar is called. My question is can i specify or manipulate statement 1 so that after bar is called it calles rock. I know i could simply have bar calle rock but thats not what i am looking for. Can bind help me accomplish this ?

James Franco
  • 4,516
  • 10
  • 38
  • 80

1 Answers1

1

std::bind won't really help here, but a lambda will.

fptr = [this](int n) { bar(n); rock(); };
aschepler
  • 70,891
  • 9
  • 107
  • 161