【发布时间】:2017-03-06 07:51:44
【问题描述】:
我有一个像这样的简单程序:
$cat testCompile.cpp
#include<stdio.h>
int fd[2];
template<int fd[]>
void f(){printf("fd\n");}
int main(){
f<fd>();
return 0;
}
编译并运行它,没问题,它只是打印“fd”。但是如果我将 fd[2] 的位置更改为 main 函数,则编译失败:
#include<stdio.h>
template<int fd[]>
void f(){printf("fd\n");}
int main(){
int fd[2];
f<fd>();
return 0;
}
clang 报告:
testCompile.cpp:6:5: error: no matching function for call to 'f'
f<fd>();
^~~~~
testCompile.cpp:3:6: note: candidate template ignored: invalid
explicitly-specified argument for template parameter 'fd'
void f(){printf("fd\n");}
^
1 error generated.
此错误表示什么?有什么问题吗?
【问题讨论】:
标签: c++ linux templates compilation clang