【问题标题】:How to define a type alias for a template in a class [duplicate]如何为类中的模板定义类型别名[重复]
【发布时间】:2017-03-03 16:57:31
【问题描述】:

例如

struct Option_1
{
    template<class T> using Vector = std::vector<T>;
};

我可以的

typename Option_1::Vector<int> v;

但我更喜欢以下

Vector<Option_1, int> v;

或没有“类型名称”一词的类似名称。我定义了一个别名

template<class Option, class T> using Vector= typename Option::Vector<T>;

但由于无法识别的模板声明/定义而失败。如何解决?

【问题讨论】:

    标签: c++ c++11 templates using type-alias


    【解决方案1】:

    您应该使用关键字template 作为依赖模板名称Option::Vector,即

    template<class Option, class T> using Vector = typename Option::template Vector<T>;
    //                                                              ~~~~~~~~
    

    LIVE

    【讨论】: