【问题标题】:What's wrong with this usage of a template `using` declaration [duplicate]模板`using`声明的这种用法有什么问题[重复]
【发布时间】:2016-07-23 01:24:27
【问题描述】:

模板using声明的以下用法有什么问题?

template <typename T1, typename T2> struct A {
    template <typename AnotherT1>
    using MyTemplate = A<AnotherT1, T2>;
};

template<class SomeA> struct B {
    using MyType = typename SomeA::MyTemplate<double>;
};

int main() {
    B<A<int, int>> b; (void)b;
}

gcc 4.8.2 抱怨:

temp.cpp:17:46: error: expected ‘;’ before ‘<’ token
     using MyType = typename SomeA::MyTemplate<double>;
                                              ^
temp.cpp:17:46: error: expected unqualified-id before ‘<’ token
temp.cpp: In instantiation of ‘struct B<A<int, int> >’:
temp.cpp:21:20:   required from here
temp.cpp:17:46: error: ‘typename A<int, int>::MyTemplate’ names ‘template<class AnotherT1> using MyTemplate = struct A<AnotherT1, int>’, which is not a type

【问题讨论】:

  • using MyType = typename SomeA::template MyTemplate&lt;double&gt;;
  • @PiotrSkotnicki 谢谢!如果您能将其作为回复,那就太好了,您可以在其中包含一个链接,我将可以在该链接中了解template这个词的用法的必要性。
  • 请参考您的重复的问题

标签: c++ templates using-declaration


【解决方案1】:

参考这个页面。 https://msdn.microsoft.com/en-us/library/0afb82ta.aspx

修改如下:

using MyType = typename SomeA::template MyTemplate<double>;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-16
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多