Question about C ++ template

I am writing some test cases for C ++ code called demangling and I get a strange error when I try to compile this: (the following is pathologically bad C ++ code that I would never use in practice).

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 }; 

The error is as follows:

  "typetest.cpp", line 165: error: nontype "Oog<T, U>::Huh<F>::Wham [with F=T]" is not a template 

Any ideas how I can fix this?

+6
source share
3 answers

The correct line should be like

 int chakka(const typename Huh<T>::template Wham<U>& wu, T t) ... it a type ^^^^^^^^ ^^^^^^^^ indicate that 'Wham' is a template 

[Note: g ++ is quite useful in this case :)]

+7
source

You need to say that the Wham member from Huh will be a template:

 const Huh<T>::template Wham<U> & 
+2
source

That should be enough (dependent types cause problems)

int chakka(const typename Huh<T>::Wham<U>& wu, T t) {}

-1
source

Source: https://habr.com/ru/post/897469/


All Articles