use*_*020 5 c++ templates using c++11 type-alias
例如
struct Option_1
{
template<class T> using Vector = std::vector<T>;
};
Run Code Online (Sandbox Code Playgroud)
我可以
typename Option_1::Vector<int> v;
Run Code Online (Sandbox Code Playgroud)
但我更喜欢下面的
Vector<Option_1, int> v;
Run Code Online (Sandbox Code Playgroud)
或不带“typename”一词的类似名称。我定义了一个别名
template<class Option, class T> using Vector= typename Option::Vector<T>;
Run Code Online (Sandbox Code Playgroud)
但由于无法识别的模板声明/定义而失败。如何修复它?
您应该使用关键字template作为依赖模板名称Option::Vector,即
template<class Option, class T> using Vector = typename Option::template Vector<T>;
// ~~~~~~~~
Run Code Online (Sandbox Code Playgroud)