【发布时间】:2015-03-12 02:37:28
【问题描述】:
尝试编译时
template<typename type,const char* format>__device__ void d_prettyPrintVector(type* v, const unsigned int size)
{
printf("\n ");
for(int i=0; i<size; i++)
printf(format, v[i]);
}
template<> void d_prettyPrintVector<float, "%4.1f ">(float*, const unsigned int);
template<> void d_prettyPrintVector<int, "%2d " >(int*, const unsigned int);
template<> void d_prettyPrintVector<char, "%2d " >(char*, const unsigned int);
template<> void d_prettyPrintVector<bool, "%d" >(bool*, const unsigned int);
并像这样使用它
d_prettyPrintVector(dc, blockDim.x);
我得到了
kernels.cu(104): error: no instance of function template "d_prettyPrintVector" matches the argument list
argument types are: (int *, const unsigned int)
怎么了?
【问题讨论】:
-
更新:不使用函数时(仅实例化模板),出现以下错误:
kernels.cu:65: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expressionkernels.cu:65: error: template-id 'd_prettyPrintVector>' for 'void d_prettyPrintVector(int*, unsigned int)' 不匹配任何模板声明` -
谢谢,这是相同的潜在问题,但解决方法不同。此外,当我问我的问题时,我看到了这个问题,但我没有看到它是如何相关的。我敢打赌,像我这样的新手会从另一个例子中受益。
标签: c++ templates cuda compiler-errors