In embedded systems, Interrupt Service Routines (ISRs) often notify the main firmware logic by calling a registered callback function. This design decouples low-level hardware events from higher-level application behavior and is commonly used in drivers and hardware abstraction layers (HALs).
Your task is to define a function pointer type alias using modern C++ syntax, select the correct callback based on a hardware mode input, and invoke the callback safely through the alias.
What You Must Do:
using keyword.void callback(int32_t code);
onError(int32_t code) — prints ERROR <code>onComplete(int32_t code) — prints COMPLETE <code>
Program Input:
Read two space-separated integers from standard input:
mode eventCodemode determines which callback to registereventCode is passed to the callback
Selection Logic:
mode == 1 → register onErrormode == 2 → register onCompleteAfter registration, invoke the callback using eventCode as the argument.
Example 1
Input:
1 42Output:
ERROR 42
Example 2
Input:
2 -5
Output:
COMPLETE -5
Constraints:
mode will always be exactly 1 or 2eventCode is a 32-bit signed integer-2,147,483,648 to 2,147,483,647using keyword to define the alias
Input
1 42
Expected Output
ERROR 42