0

以下使用模板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 ‘&lt;’ token
     using MyType = typename SomeA::MyTemplate<double>;
                                              ^
temp.cpp:17:46: error: expected unqualified-id before ‘&lt;’ 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
4

1 回答 1

0

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

修改如下:

using MyType = typename SomeA::template MyTemplate<double>;
于 2016-04-03T14:54:06.643 回答