How to pass a non static function as argument

How to pass a non static function as argument?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct A{
  void a(void b()){
    b();
  }
};

struct B{
  void b(){}

  B(){
    A a;
    a.a(b);
  }
};

int main(){
  B b;
}


Thank you for your help!
Use std::function and keep in mind that an extra first argument is added - this is the object on which to act.
http://www.cplusplus.com/reference/functional/function/
http://en.cppreference.com/w/cpp/utility/functional/function

Alternatively, you can learn about how pointers-to-members and pointers-to-member-functions are entirely different beasts from function pointers.
http://www.parashift.com/c++-faq/pointers-to-members.html
Last edited on
Topic archived. No new replies allowed.