#include <iostream>
#include <cstdint>

using namespace std;

using ISRCallback = void(*)(int32_t );
// 1. Create the function pointer alias here using 'using'
// using ISRCallback = ...

void onError(int32_t code) {
    cout << "ERROR " << code;
}

void onComplete(int32_t code) {
    cout << "COMPLETE " << code;
}

int main() {
    int32_t mode, eventCode;
    if (!(cin >> mode >> eventCode)) return 0;

    ISRCallback cb = nullptr;
    // 2. Declare a variable using your alias and initialize to nullptr
    // ISRCallback cb = nullptr;
    if(mode == 1)
        cb = onError;
    else
        cb = onComplete;
    // 3. Register the correct function based on mode
    // if (mode == 1) ...
    // else if (mode == 2) ...
    cb(eventCode);
    // 4. Invoke the callback
    // if (cb) ...

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

1 42

Expected Output

ERROR 42