c++ - extern struct forward declaration
问题描述
I am trying to compile some old code that include a mix of C and C++. I found following syntax:
extern struct Edge;
typedef struct Edge
{
...
Edge* edges;
...
} Edge;
When I try to compile with GCC I get an error:
a storage class can only be specified for objects and functions
extern struct Edge;
After I remove extern it compiles. I might be mistaken, but it does look to me like a forward declaration of Edge, but why there an extern
keyword at the front of struct
?
解决方案
在 C 中,是有效的但没有用:它的含义与Inextern struct S;
完全相同,适用于, , , ... 无论声明了多少变量,即使声明了零个变量。struct S;
extern struct S a, b, c, ...;
extern
a
b
c
在 C++ 中,extern struct S;
无效。为了与 C 兼容,大多数 C++ 编译器都允许它作为扩展,但 GCC 不允许。您只是删除了extern
关键字是对的。
可能最初编写的代码extern struct S s;
被拆分为 and 的单独声明struct S
,s
并且extern
不小心留下了。由于编译器不介意,所以作者没有注意到。
推荐阅读
- javascript - Nuxt.js:全局 mixin 仅在服务器端工作
- reporting-services - 列超链接并将数据从主报告传递到其他报告
- arduino - 在与 HC-05 的 Arduino 连接中,串行通信无法正常工作
- java - 从 webapplicationexception 返回 JSON 正文中的错误
- angular - 角度没有主体的发布方法
- python-3.6 - 匹配后,使用python获取文件中的下一行
- wordpress - 我将如何扩展木材以能够将手柄用作包含中的参考?
- swift - 如何更新此类以支持将键路径值绑定到函数?
- python - 如何计算数据框中另一列中每个唯一值对应的值?
- unity3d - 使用 MRTK 坐在封闭式 VR 中玩游戏时如何调整角色高度?