模板的typedef
问题描述:
可能重复:
C ++ template typedef
我试图导出另一个模板的模板类型通过预先专门化另一模板:
I am trying to derive a template type of another template by pre-specializing of 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;
但是,在GCC 4.4.5,我得到这个错误:错误:第二种类型(
。 test01
)上的typedef模板声明
However, on GCC 4.4.5, I am getting this error: error: template declaration of ‘typedef’
on the second type (test01
).
答
不允许使用此语法由C ++ 03。最近的解决方法是:
This syntax isn't allowed by C++03. The nearest work-around is:
template<unsigned c>
struct test01
{
typedef test<0, 1, c> type;
};
typedef test01<2>::type my_type;
在C ++ 0x中,我们可以这样做:
In C++0x, we can do this:
template<unsigned c>
using test01 = test<0, 1, c>;