Lei*_*sen 0 c c++ compiler-errors header
我有一个头文件BKE_mesh.h的以下块:
/* Connectivity data */
typedef struct IndexNode {
struct IndexNode *next, *prev;
int index;
} IndexNode;
void create_vert_face_map(ListBase **map, IndexNode **mem, const struct MFace *mface,
const int totvert, const int totface);
void create_vert_edge_map(ListBase **map, IndexNode **mem, const struct MEdge *medge,
const int totvert, const int totedge);
Run Code Online (Sandbox Code Playgroud)
请注意,头文件是为准备在C++文件中使用而准备的,因为它具有:
#ifdef __cplusplus
extern "C" {
#endif
Run Code Online (Sandbox Code Playgroud)
在文件的顶部,以及底部所需的完成.但实现它的类是用C语言编写的.
接下来,每当我尝试#include头文件时,我都会遇到奇怪的错误.如果文件的扩展名为.cpp,则编译得很好,没有任何投诉.但是,如果我这样做:
#include "BKE_mesh.h"
Run Code Online (Sandbox Code Playgroud)
在.c扩展名的文件中,我收到以下错误:
expected ')' before '*' token
Run Code Online (Sandbox Code Playgroud)
对于最后两个函数,具体来说,变量:
ListBase **map
Run Code Online (Sandbox Code Playgroud)
在这两个班级.(注意,在头文件的早期,它已声明,但未定义ListBase).
所以,我的问题是:为什么这是有效的C++代码,而不是C代码?
谢谢.
在C++中,您可以直接引用结构名称,但在C中您需要添加关键字struct.
void create_vert_face_map(struct ListBase **map, ... );
Run Code Online (Sandbox Code Playgroud)
您可以通过添加typedef来解决这个问题.然后你不必修改函数声明.
typedef struct ListBase ListBase;
Run Code Online (Sandbox Code Playgroud)