【发布时间】: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<double>; -
@PiotrSkotnicki 谢谢!如果您能将其作为回复,那就太好了,您可以在其中包含一个链接,我将可以在该链接中了解
template这个词的用法的必要性。 -
请参考您的重复的问题
标签: c++ templates using-declaration