如何为类中的模板定义类型别名

时间:2017-03-03 16:57:32

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

例如

Select position.id, firstname, lastname, 'cook' AS position
FROM position LEFT JOIN people ON position.cook = people.id

UNION

Select position.id, firstname, lastname, 'teacher' AS position
FROM position LEFT JOIN people ON position.teacher = people.id

UNION
...

我能做到

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

但我更喜欢以下

typename Option_1::Vector<int> v;

或没有单词“typename”的类似物。我定义了一个别名

Vector<Option_1, int> v;

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

1 个答案:

答案 0 :(得分:3)

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

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

LIVE