How can I call a function using a function pointer?

前端 未结 16 1679
孤独总比滥情好
孤独总比滥情好 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:49

    You can declare the function pointer as follows:

    bool (funptr*)();
    

    Which says we are declaring a function pointer to a function which does not take anything and return a bool.

    Next assignment:

    funptr = A;
    

    To call the function using the function pointer:

    funptr();
    

提交回复
热议问题