1
我使用模板的模板参数如下:C++ 11转发模板的模板参数不起作用
/* [1]: Definition containing a template template parameter */
template <typename T, template<class> class Kernel>
void ForEach(Kernel<T> kernel, T * pSrc, int elementCount) {
//....
}
/* [2]: Definition of a helper struct */
template <typename T> struct KernelStd {
//...
};
/* [3]: Use the previous definitions */
float arr1[5] = {1,2,3,4,5};
//The following two calls to ForEach do successfully compile
ForEach(KernelStd<float>(), arr1, 5); //USE1
ForEach<float>(KernelStd<float>(), arr1, 5); //USE2
/* [4]: Definition of a helper function */
template <typename F, typename ...Args>
void forwarder(F func1, Args && ...args) {
//...
func1(std::forward<Args>(args)...);
}
//But the following callS do not compile.
forwarder(ForEach, KernelStd<float>(), arr1, 5); //USE3
forwarder(ForEach<float>, KernelStd<float>(), arr1, 5); //USE4
我使用VS2013更新5,我得到以下错误:
error C2783: 'void ForEach(Kernel<T>,T *,int)' : could not deduce
template argument for 'Kernel'
任何帮助将不胜感激。
什么是ForEach?它在某种程度上与“转化”有关吗?什么是KernelStd?它是否以某种方式与'Kernel1'相关?如果你显示[一个MCVE](https://stackoverflow.com/help/mcve) –
谢谢你指出我的代码片段中的错误。我已经修复了这些。 – fonishormon