Template alias for another alias

I have a problem with the 'using' keyword in C ++ 11. This piece of code should create an alias for a pointer to another type.

template <typename T> class SomeClass { typedef typename std::add_pointer<T>::type pointer; template <typename U> using rebind_pointer = typename std::pointer_traits<pointer>::rebind<U>; } SomeClass<int> obj; 

But in gcc 4.7 I have a compilation error:

typename std::pointer_traits<int*>::rebind names template<class _Up> using rebind = _Up* , which is not a type

I found out that pointer_traits :: rebind is its own template alias, so maybe this is a problem?

+6
source share
1 answer

You should tell the compiler to parse rebind as a template:

 template <typename U> using rebind_pointer = typename std::pointer_traits<pointer>::template rebind<U>; // ^^^^^^^^ 

This is necessary because std::pointer_traits<pointer> depends on the template parameter ( T ).

For more information about when and why you need to use the template keyword, see this question .

+9
source

All Articles