请考虑以下代码
template <typename T, T one>
T exponentiel(T val, unsigned n) {
T result = one;
unsigned i;
for(i = 0; i < n; ++i)
result = result * val;
return result;
}
int main(void) {
double d = exponentiel<double,1.0>(2.0f,3);
cout << d << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器告诉我这个调用'exponentiel(float,int)'没有匹配函数
为什么?
奇怪的是exponentiel与int一起工作.