How can I call a function using a function pointer?

前端 未结 16 1665
孤独总比滥情好
孤独总比滥情好 2020-12-02 17:24

Suppose I have these three functions:

bool A();
bool B();
bool C();

How do I call one of these functions conditionally using a function poi

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 17:45

    I think your question has already been answered more than adequately, but it might be useful to point out explicitly that given a function pointer

    void (*pf)(int foo, int bar);
    

    the two calls

    pf(1, 0);
    (*pf)(1, 0);
    

    are exactly equivalent in every way by definition. The choice of which to use is up to you, although it's a good idea to be consistent. For a long time, I preferred (*pf)(1, 0) because it seemed to me that it better reflected the type of pf, however in the last few years I've switched to pf(1, 0).

提交回复
热议问题