Search code examples
c++templatestypedefusing

Nested template using/typdef


Say I have this setup:

template<typename T1>
struct A {
  template<typename T2>
  struct B {
    using type = int;
  };
};

I'd like to be able to form a typdef/using:

template<typename T1,typename T2>
using type2 = A<T1>::B<T2>::type;
//... and use like
type2<int,char> foo;

GCC complains that I need typename A<T1>::B<T2>::type instead, and afterwards complains that it expects ";" before "<" after B (i.e. typename A<T1>::B)

is there no way to use "using" with nested templates?


Solution

  • Switch from

    using type2 = A<T1>::B<T2>::type;
    

    to

    using type2 = typename A<T1>::template B<T2>::type;