模板的typedef [英] Template typedef of a template

查看:163
本文介绍了模板的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>;

这篇关于模板的typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆