c – typedefing枚举问题.和visual studio 2005中的bug
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 namespace B::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的第一句话,现在说
但它曾经说过
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |