我今天在C11中使用using关键字有一个问题.我决定现在使用另一种方法(在下面的例子中添加注释).您可以将X作为矩阵,将Y作为混合,并且目的是在Y中访问X的转置矩阵类型.而不是类型定义X
中,我们采用另一种更强大的方法,并定义了一个自己拥有两个模板参数的兄弟姐妹别名.
template <class A,class B> struct X { using Left = A; using Right = B; template <class T1,class T2> using Sibling = X<T1,T2>; // using Reversed = X<B,A>; // What I really want and use Now. :-) }; template <class A> struct Y { using Left = typename A::Left; using Right = typename A::Right; using AReverse = typename A::Sibling<Right,Left>; // Gives a compiler error // using AReverse2 = typename A::Reversed; // Works,of course. }; using Z = X<int,double>::Sibling<double,int>; // Works
我试图用g -4.7 -std = c 11 -c编译上面的代码,并显示以下错误消息:
t.cpp:16:9: error: expected nested-name-specifier before ‘AReverse’ t.cpp:16:9: error: using-declaration for non-member at class scope t.cpp:16:18: error: expected ‘;’ before ‘=’ token t.cpp:16:18: error: expected unqualified-id before ‘=’ token
我不明白为什么会得到一个错误信息,或者我如何解决它.有人可以向我解释问题是什么?
非常感谢!
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。