type alias declaration for function pointer without parameters

Advertisements

From Cppreference – Type alias I know that following type alias declaration works:

using func = void (*) (int, int);

How does the equivalent for a function pointer to a class member look like?

>Solution :

You just need to add a qualifying class name before the *.

For example using func = void (foo::*)(int, int);

Demo :

struct foo
{
    void bar(int, int);
};

using func = void (foo::*)(int, int);

func ptr = &foo::bar;

Leave a Reply Cancel reply