example1_simple_callback_using_function_pointer.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>

// A simple function that takes a callback
void process(int x, void (*callback)(int)) {
    std::cout << "Processing value: " << x << std::endl;
    callback(x);  // Invoke the callback function
}

// A callback function
void myCallback(int result) {
    std::cout << "Callback called with value: " << result << std::endl;
}

int main() {
    int value = 42;
    process(value, myCallback);  // Pass the callback function
    return 0;
}
Back to callbacks