Search code examples
c++c++17function-pointerstypedef

How can I declare multiple function pointer types in one typedef declaration?


I can do

typedef int a, b;

but I can't do something like

typedef void(*the_name_1, *the_name_2)(...);

Is there a way do to typedef 2 function pointer types at the same time ?


Solution

  • Multiple declaration in C/C++ is misleading as * is linked to variable and not to the type:

    typedef int a, *b, (*c)();
    
    static_assert(std::is_same_v<int, a>);
    static_assert(std::is_same_v<int*, b>);
    static_assert(std::is_same_v<int (*)(), c>);
    

    So your one-liner would be

    typedef void(*the_name_1)(...), (*the_name_2)(...);