typedef using template arguments not working with g++

c++, c++11

Solution

Based on the gcc error message, the problem is you claim `A<T>::B` is a type but it isn't: it a class template. Both gcc and clang are happy with

typedef A<T>::B<T> Ttype;

i.e., remove the `typename`. In the given context it wouldn't be possible to specialize `B` to be something different than what it obviously is anyway.

The `using`-alias does just the same with a different syntax:

using Ttype = A<T>::B<T>;

The notation using an extra `template` keyword first states that `B` is actually a `template` and then, in combination with the `typename` that the instantiation `B<T>` is a type:

typedef typename A<T>::template B<T> Ttype;

or

using Ttype = typename A<T>::template B<T>;

Since the class template `B` is local anyway, the qualification isn't really needed in this context, i.e.

typedef B<T> Ttype;

and

using Ttype = B<T>;

do work as well.

Problem

The following code compiled under MVCC but not g++, and i'm not sure why. ``` template <typename T> class A { public: template <typename C> class B { public: C* cptr; }; typedef typename A<T>::B<T> Ttype; }; int main(int argc,char** argv) { A<int>::Ttype d; d.cptr = 0; } ``` with g++, you get ``` error: 'typename A<T>::B name template<class T> template<class C> class A<T>::B', which is not a type ``` I am compiling with -std=c++11

Original source