【发布时间】:2011-06-27 10:32:12
【问题描述】:
可能重复:
C++ template typedef
我正在尝试通过预先特化另一个模板来派生另一个模板的模板类型:
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 上,我收到此错误:error: template declaration of ‘typedef’ 第二种类型 (test01)。
非常感谢您的指导,因为我不明白我的代码有什么问题。
【问题讨论】:
-
我知道这是重复的,但我找不到。编辑:啊哈,here.
-
请下次使用搜索
-
当您查看副本时,请注意在这种特殊情况下,用户不想使用继承,即使这是 C++98 编译器的常见模式:
template <unsigned c> struct test01 : test<0,1,c> {}略有不同,因为您正在向混合中添加继承并且有一些陷阱(注意:不要通过指向test<0,1,N>的指针删除类型,因为这会导致 UB,始终在test01级别销毁)