使用type = smth。和模板类型

时间:2013-10-30 15:38:55

标签: c++ templates c++11 using

我在使用一段C ++代码时遇到了一些麻烦。

首先,如果我这样做,它的效果非常好:

struct A
{
    using my_type1 = double;
    using my_type2 = int;
};

struct B
{
    using size_type = A::my_type2;
};

但是,我希望能够选择my_type1,所以我采用了模板方式:

template <typename T>
struct A
{
    using my_type1 = T;
    using my_type2 = int;
};

template <typename T>
struct B
{
    using size_type = A<T>::my_type2;
};

这里,gcc失败了:行上的“预期类型说明符”

using size_type = A<T>::my_type2;

我也可以将my_type2放在模板中,但这是一种不应该改变的类型。

那为什么我的方法不起作用?谢谢!

1 个答案:

答案 0 :(得分:1)

您必须添加typename

using size_type = typename A<T>::my_type2;