How do I typedef a function pointer with the C++11 using syntax?

rubenvb picture rubenvb · May 11, 2013 · Viewed 61.9k times · Source

I'd like to write this

typedef void (*FunctionPtr)();

using using. How would I do that?

Answer

0x499602D2 picture 0x499602D2 · May 11, 2013

It has a similar syntax, except you remove the identifier from the pointer:

using FunctionPtr = void (*)();

Here is an Example

If you want to "take away the uglyness", try what Xeo suggested:

#include <type_traits>

using FunctionPtr = std::add_pointer<void()>::type;

And here is another demo.