gpt4 book ai didi

c++ - 没有匹配函数来调用函数模板

转载 作者:太空狗 更新时间:2023-10-29 20:17:51 28 4
gpt4 key购买 nike

template<class T, T i> void f(int[10][i]) { };

int main() {
int a[10][30];
f(a);
}

为什么 f(a) 会失败?

http://ideone.com/Rkc1Z

最佳答案

f(a)失败,因为无法从非类型参数的类型推导出模板类型参数。在这种情况下,编译器无法推断模板参数的类型 T .

尝试将其称为 f<int>(a);

关于c++ - 没有匹配函数来调用函数模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5771314/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com