How to declare a function pointer in C / C ++

    3 answers 3

    You must adhere to the following ad form:

    typedef тип_возвращаемого_значения (*имя_указ)(список_параметров_функции); 

    For example:

     typedef int (*pfn)(int param1, void * param2); 

      Starting from you can declare via using :

       using name = retType(*)(params); 


       void f(int, int) {} // функция приемлимой сигнатуры using FP = void(*)(int, int); // объявление типа указатель на функцию FP fp = f; // определение и инициализация fp(42, 100500); // вызов функции через указатель 

        Very handy thing (but, of course, this does not apply to Pure C, which was in the labels). Here you have both pointers to functions, and to class methods, and to functors (!), And all sorts of mutks with bind and place-holders.