The goal is to change the behaviour in an event loop, depending on whether a checkbox is toggled on or off. The simplest way, that I can think of, is just to test the checkbox state each time the loop is run.
// if-statement
void action() { /* ... */ }
void someLoop() {
if (checkboxTrue) {
action();
}
// ... other stuff
}
Would the code be more performant and cleaner or in any other way better, if a function pointer was being used? Like this:
// function pointer
void action() { /* ... */ }
void empty() {}
void (*actionPtr)();
void checkboxChanged(int val) {
if (val == 1)
actionPtr = &realAction;
else
actionPtr = ∅
}
void someLoop() {
(*actionPtr)();
// ... other stuff
}