I want to create a "grand total" function by summing several other functions together. This can be done at compile time, so I thought a recursive variadic function template would be a good solution. My code so far:
int One(){return 1;}
int Two(){return 2;}
int Three(){return 3;}
using func_t = int(void);
//Base case
template <func_t F>
int Total() {
return F();
}
template <func_t F, func_t... Fs>
int Total() {
return F() + Total<Fs...>();
}
int main(int argc, char *argv[])
{
cout << Total<One, Two, Three>() << endl;
return 0;
}
However, I get MSVC compiler error C2668: 'Total': ambiguous call to overloaded function; could be int Total<int Three(void),>(void)
or int Total<int Three(void)>(void)
I don't understand why the compiler has two similar candidates for my function template, the only difference being that one has an extra comma.