Typedef template

Possible duplicate:
C ++ template typedef

I am trying to get a template template of another template by pre-specializing another template:

template<unsigned a, unsigned b, unsigned c>
struct test
{
    enum
    {
        TEST_X = a,
        TEST_Y = b,
        TEST_Z = c,
    };
};

template<unsigned c>
typedef test<0, 1, c> test01;

However, in GCC 4.4.5, I get this error: error: template declaration of ‘typedef’for the second type ( test01).

The manual will be highly appreciated since I do not understand what is wrong with my code.

+5
source share
2 answers

This syntax is not allowed by C ++ 03. Nearest work:

template<unsigned c>
struct test01
{
    typedef test<0, 1, c> type;
};

typedef test01<2>::type my_type;

In C ++ 0x, we can do this:

template<unsigned c>
using test01 = test<0, 1, c>;
+10
source

Just to list the alternatives:

template <typename C>
struct test01 : test<0, 1, C> { };

test01<4> my_test014;

This creates new, crisp types, and not just aliases for instances of the base template: - (.

+2
source

All Articles