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