You have to put template
before the method name:
B(): b(T::template a<double>(5)) {}
This is because when the template class B
is being parsed, the compiler does not know that T::a
is a templated method (since T
is not specified until then, and T::a
is completely unknown), so it doesn't know that <double>
should be parsed as a template parameter list.
It could also mean and will indeed be parsed as: T::a
less than double
greater than (0)
. Of course, double
isn't an expression, so this failes; thus the error message. So the compiler could just assume that you want it to be a templated function call. But you can also have a non-type template parameter, let's say for example an int, so T::a<42>(5)
can be parsed as T::a
less than 42
greater than (5)
, which isn't a template. But you wanted it to be parsed as T::a
then a template parameter list with the parameter 42
and then the call-operator with an argument 5
.
To tell the compiler that it's a templated function call, you have to put template
before the function name.