Function callbacks

I wanted some help trying to create a callback function with C++. Below is a header file and I would like to make test_callback () a callback function, but do not know where to begin. Can you please advise?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef FOO_H_
#define FOO_H_

typedef struct {
  int data1;
  int data2;
  char data3;
  double data4;
} MyData;

class Foo
{
 public:
  Foo ();
  ~Foo ();

  // i want to make this function into a callback
  void test_callback (MyData *data);
};

#endif /* FOO_H_ */ 

Couldn't test it, I hope it's correct, and I also hope this is what you meant.
1
2
3
4
5
6
7
8
typedef void (Foo::*call_back_function_type)(MyData*);

call_back_function_type f = &Foo::test_callback;

Foo x;
MyData data;
(x.*f)(&data);
Topic archived. No new replies allowed.