Implement function callbacks in c and c++

  • 2020-04-02 01:14:39
  • OfStack

Using function Pointers as struct members enables function registration and callbacks

struct T
{
 void (*callback)(char *);
};
void doSomething(char *job)
{
 //TODO...
}
int main()
{
 T t;
 t.func = doSomething;
 //Call the callback function
 t.func("something");
 return 0;
}


Related articles: