How typedef works for function pointers

后端 未结 4 1125
名媛妹妹
名媛妹妹 2020-11-29 07:54

I think I may be suffering from the dreaded \"accidental programmer\" disease, at least when it comes to typedefs and function pointers. So I\'ve been experimenting with all

4条回答
  •  一向
    一向 (楼主)
    2020-11-29 08:32

    Like C, C++ has pointer to functions: void (*)() for example is a pointer to a function that takes no argument and returns no value. However, C++ has also introduced references to functions void (&)() and there are implicit conversions between the two (though I don't remember the rules exactly).

    Therefore:

    • funcname is a reference to function
    • &funcname is a pointer to function

    Note that taking the address (or a reference to) a function that is overloaded requires a static_cast to the exact type (to resolve the overload).

提交回复
热议问题