GCC不會編譯下面的代碼片段(這實際上是GCC的正確行爲,因爲它是符合標準的C++,因爲我已經學會了。VC++但將編譯)呼叫從一個模板類中的模板功能
template<class T>
void CUDAMemory1D2DTextureAllocator<T>::allocateMemoryOnDevice()
{
m_pChannelDesc = cudaCreateChannelDesc<T>();
...
}
正如我已經發現通過搜索是,那個人需要告訴編譯器cudaCreateChannelDesc
是一種模板方法。否則,它會嘗試 解析<
作爲比運營商更小的...
下面的代碼片段顯示,在一個簡單的例子:
template< typename G >
struct Test
{
template< typename T > T f() const;
};
template< typename G, typename T >
void g()
{
Test<G> t;
t.f<T>(); // ERROR: gcc won't compile that
t.template f<T>(); // OK: now gcc knows that f is a template method an treads the following angle brackets not as operators but as template brackets...
}
到目前爲止好。現在我的問題是,在上述情況下如何做到這一點,我調用的方法是cudaCreateChannelDesc
,它不屬於任何類或名稱空間? 任何意見或建議如何解決這種情況是非常受歡迎的。
感謝
你只需要`模板`而不是創建臨時模板。你有, – GManNickG 2011-01-24 07:46:33