6

I have some problem with 'using' keyword in c++11. This piece of code should create alias for 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've got compile 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 a template alias itself so maybe that is problem ?

Martin York
  • 257,169
  • 86
  • 333
  • 562
eupp
  • 535
  • 3
  • 13

1 Answers1

9

You need to 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> is dependent on a template parameter (T).

See this question for more details about when and why you need to use the template keyword.

Community
  • 1
  • 1
TartanLlama
  • 63,752
  • 13
  • 157
  • 193