可能重复:
C++模板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;
Run Code Online (Sandbox Code Playgroud)
但是,在GCC 4.4.5上,我收到了这个错误:error: template declaration of ‘typedef’
在第二个类型(test01
)上.
我非常感谢指导,因为我不明白我的代码有什么问题.
GMa*_*ckG 10
C++ 03不允许使用此语法.最近的解决方法是:
template<unsigned c>
struct test01
{
typedef test<0, 1, c> type;
};
typedef test01<2>::type my_type;
Run Code Online (Sandbox Code Playgroud)
在C++ 0x中,我们可以这样做:
template<unsigned c>
using test01 = test<0, 1, c>;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2930 次 |
最近记录: |