[英]C++ template question
我正在為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
我有什么想法可以解決?
正確的行應該是,
int chakka(const typename Huh<T>::template Wham<U>& wu, T t) ...
it's a type ^^^^^^^^ ^^^^^^^^ indicate that 'Wham' is a template
[注意: 在這種情況下,g ++非常有用 :)]
你需要告訴它,Huh的Wham成員將成為一個模板:
const Huh<T>::template Wham<U> &
這應該足夠了(依賴類型引起麻煩)
int chakka(const typename Huh<T>::Wham<U>& wu, T t) {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.