Take the 2-minute tour ×

What is the difference between below syntax:

template<typename T>
struct A { ... };

A<void (*)()> o1; // <--- ok
A<void()> o2;  // <----- ??

I want to know the practical use of the 2nd syntax apart from libraries (I checked that we cannot declare object of void() inside A). I have referred this question, but that din't help.

share|improve this question

1 Answer 1

void() is the type of a function taking no arguments, and returning nothing.

void(*)() is the type of a pointer to a function taking no arguments, and returning nothing.

As an example of where void() is used and is useful, look at std::function -- the syntax it uses is much nicer than if you had to pass in a function pointer signature. You can use the exact same syntax when you mean "I want to tell this template class the signature of a call".

Mainly, this is just syntactic sugar. But sugar is the spice of life.

share|improve this answer

Your Answer


