
struct A{ enum E { FirsT,SECOND };};struct B{ typedef A::E E;};int main(){ B::E e0 = A::FirsT;//OK (this case is clear for me) B::E e1 = A::E::FirsT;//OK (this case is clear for me as well) B::E e2 = B::FirsT;//Compile Error: FirsT is not member of B (Why isn't this allowed? Don't we lose meaning of typedef of enums in this case?) B::E e3 = B::E::FirsT;//Error of compiler (If there were no BUG in visual studio 2005 compiler,would this code work?) return 0;} 附:代码中的问题.
更新:实际上该错误已在VS2010中修复.
解决方法 在B :: E e3 = B :: E :: FirsT中添加缺少的分号后,以下内容成立:在C 03中,只有第一行(B :: E e0 = A :: FirsT;)是正确的,其他三个是错误:
B::E e1 = A::E::FirsT; // error: ‘A::E’ is not a class or namespaceB::E e2 = B::FirsT; // error: ‘FirsT’ is not a member of ‘B’B::E e3 = B::E::FirsT; // error: ‘B::E’ is not a class or namespace
在C 0x中,只有第二行(B :: E e2 = B :: FirsT;)是一个错误(FirsT仍然不是B的成员!),其他三个是正确的.
不是“为什么?”的答案,只是指出手头有两个不同的问题.影响e1和e3的问题的基本原理可能在C 0x工作文件中有所解释.
改变是3.4.3 [basic.lookup.qual] / 1的第一句话,现在说
The name of a class or namespace member or enumerator can be referred to after the :: scope resolution operator
但它曾经说过
总结The name of a class or namespace member can be referred to after the :: scope resolution operator
以上是内存溢出为你收集整理的c – typedefing枚举问题.和visual studio 2005中的bug全部内容,希望文章能够帮你解决c – typedefing枚举问题.和visual studio 2005中的bug所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)