使用可选的’struct’关键字时c – g警告
发布时间:2020-12-16 05:32:38 所属栏目:百科 来源:网络整理
导读:如果我写这个程序: #include iostreamnamespace foo { struct bar { int x; };}int main (void) { struct foo::bar *a = new struct foo::bar; delete a; return 0;} 并编译: g++ main.cxx -Wall -Wextra 它给我这个警告: main.cxx: In function ‘int ma
如果我写这个程序:
#include <iostream> namespace foo { struct bar { int x; }; } int main (void) { struct foo::bar *a = new struct foo::bar; delete a; return 0; } 并编译: g++ main.cxx -Wall -Wextra 它给我这个警告: main.cxx: In function ‘int main()’: main.cxx:10:39: warning: declaration ‘struct foo::bar’ does not declare anything [enabled by default] 但是,如果我在new关键字后面取出了struct关键字: #include <iostream> namespace foo { struct bar { int x; }; } int main (void) { struct foo::bar *a = new foo::bar; delete a; return 0; } 并以相同的方式编译,g不输出警告.为什么g输出警告如果我使用struct关键字? 解决方法
在C中,struct关键字定义一个类型,新类型不再需要struct关键字.这是C和C之间的许多区别之一.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |