GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, March 1, 2011

Callback Function With Parameter Argument

#include <iostream>

/**
 * Callback function need two function:
 * 1. caller function - display();
 * 2. called function - hello();
 *
 * Caller function just a function that has task to call
 * the another function while the called function is 
 * what the function we define and we write.
 *
 * parameter supplied by the program or api. not you as programmer
 *
 */

using namespace std;

/**
 * This function is like main entry function
 */
void hello(int c){
    cout << c << endl;  // print out 45
}

void display(void(*func)(int)){
    int def = 45;
    func(def);
}

int main(int argc, char *argv[]){
    display(hello);
}

Share/Bookmark

No comments:

Post a Comment