我正在爲C++ name-demangling代碼編寫一些測試用例,並且在嘗試編譯時出現一個奇怪的錯誤:(以下是我在實踐中從不會使用的病態的錯誤C++代碼)。C++模板問題
template<class U, class V>
class TStruct
{
U u;
V v;
public:
void setU(const U& newu) {u = newu; }
};
template<class T, class U>
class Oog
{
T t;
U u;
public:
Oog(const T& _t, const U& _u) : t(_t), u(_u) {}
void doit(TStruct<T,U> ts1, TStruct<U,T> ts2, U u1, T t1) {}
template<class F>
class Huh
{
F f;
public:
template<class V>
class Wham
{
V v;
public:
Wham(const V& _v) : v(_v) {}
void joy(TStruct<T,V> ts1, U u, F f) {}
};
};
int chakka(const Huh<T>::Wham<U>& wu, T t) {} // error here
};
錯誤如下:
"typetest.cpp", line 165: error: nontype "Oog<T, U>::Huh<F>::Wham [with F=T]"
is not a template
任何想法如何,我可以修復?
謝謝!我知道'typename',但不知道你必須以這種方式使用'template'關鍵字。 –
+1:另一個很好的答案!這周至少有兩次! :D –
@Tomalak,你給出了「很好的回答」評論,然後在有人反對之後收回你的投票/評論! – iammilind