Can a function type be a class template parameter?

Variables cannot have function types. You declare bar to be FunctionPtr which is decltype(Hello) which evaluates to int (int), not a function pointer type.

It's confusing because of some inconsistencies inherited from C. When you define the constructor for A as taking a FunctionPtr you might imagine you'd get the same error. However, function parameters declared as having an array or function type automatically (unfortunately, inconveniently) get turned into pointer types. So even though foo is declared to have a function type it actually has function pointer type and works fine.

But this rule applies only to function parameters and not other variables, so bar actually does have a function type, which is not legal.


gcc is a bit more friendly regarding this error :

error: field 'A<int(int)>::bar' invalidly declared function type

The simplest solution is to declare bar as a function pointer :

FunctionPtr *bar;

In this case, decltype(Hello) evaluates to int(int) not int(*)(int).