【问题标题】:Nested class template type alias嵌套类模板类型别名
【发布时间】:2021-05-28 11:59:02
【问题描述】:

这可能是一个简单的问题,但我似乎无法弄清楚为嵌套类模板定义类型别名的语法。

基本上,我有:

template<class T>
struct Outer {
    template<class U = T>
    struct Inner {};
}

我希望能够从类定义外部访问 Inner 类作为类型。 我试过了:

template<class T> 
using Inner = typename Outer<T>::Inner;

template<class T, class U = T> 
using Inner = typename Outer<T>::Inner<U>;

但这没有用。

这实际上应该怎么做?

【问题讨论】:

    标签: c++ inner-classes type-alias


    【解决方案1】:

    你需要额外的template:

    template<class T, class U = T> 
    using Inner = typename Outer<T>::template Inner<U>;
    

    Demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2011-03-26
      相关资源
      最近更新 更多