我正在为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