小编Jus*_*tin的帖子

C++模板:没有匹配的调用函数

请考虑以下代码

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一起工作.

c++ templates

4
推荐指数
1
解决办法
1473
查看次数

标签 统计

c++ ×1

templates ×1