Using Function Pointers for Callbacks - C++ Data Type

C++ examples for Data Type:typedef

Description

Using Function Pointers for Callbacks

Demo Code

#include <iostream>

bool updateProgress(int pct) {
   std::cout << pct << "% complete...\n";
   return(true);
}

typedef bool (*FuncPtrBoolInt)(int);

void longOperation(FuncPtrBoolInt f) {
   for (long l = 0; l < 100000000; l++)
      if (l % 10000000 == 0)
         f(l / 1000000);/*  w  w  w . ja  v a 2 s.com*/
}

int main() {
   longOperation(updateProgress); // ok
}

Result


Related Tutorials