Consider the following code, which does not use a typedef:

int do_math(float arg1, int arg2) {
    return arg2;
}

int call_a_func(int (*call_this)(float, int)) {
    int output = call_this(5.5, 7);
    return output;
}

int final_result = call_a_func(&do_math);

This code can be rewritten with a typedef as follows:

typedef int (*MathFunc)(float, int);

int do_math(float arg1, int arg2) {
    return arg2;
}

int call_a_func(MathFunc call_this) {
    int output = call_this(5.5, 7);
    return output;
}

int final_result = call_a_func(&do_math);

ref:
https://en.wikipedia.org/wiki/Typedef
arrow
arrow
    全站熱搜

    天才R 發表在 痞客邦 留言(0) 人氣()