c++ - 错误 C2143 : syntax error : missing '{' before '*'

标签 c++ c

struct reprVectorsTree;

#ifdef __cplusplus
extern "C" {
#endif

typedef reprVectorsTree * RHandle;
RHandle create_reprVectorsTree(float **, int , int );
void free_reprVectorsTree(RHandle);
float*  work_decode(RHandle , bool*, int);

#ifdef __cplusplus
}
#endif

我是按照这里的回答写的接口(interface)头文件 How to use c++ objects in c? ,但我收到语法错误?缺少什么?

----编辑---- 我改成了

struct reprVectorsTree;

#ifdef __cplusplus
extern "C" {
#endif

typedef struct reprVectorsTree * RHandle;
RHandle create_reprVectorsTree(float **, int , int );
void free_reprVectorsTree(RHandle);
float*  work_decode(RHandle , bool *, int);

#ifdef __cplusplus
}
#endif

现在我在 float* 行上收到以下错误

error C2143: syntax error : missing ')' before '*'
error C2081: 'bool' : name in formal parameter list illegal
error C2143: syntax error : missing '{' before '*'
error C2059: syntax error : ','
error C2059: syntax error : ')'

最佳答案

尝试:

typedef struct reprVectorsTree * RHandle;

你不能只使用一个结构,就好像它是 C 中没有 typedef 的类型(例如 typedef struct reprVectorsTree; )

编辑:您还需要 #include <stdbool.h>对于 bool假设你使用的是最新的 C 编译器,或者只使用 int相反。

关于c++ - 错误 C2143 : syntax error : missing '{' before '*' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11993101/

相关文章:

c++ - 即使未选中复选框,也可以使用 DateTimePicker 控件检索日期

c++ - 图像颜色转换

c++ - 声明一个接受泛型迭代器的函数

c++ - 通过 SYSTEMTIME 检查文件的 LastWriteTime 是昨天

c++ - 如何探测 std::mutex?

c - 包含的 C 文件中的 Pragma

c - 如何将数组中的字符串分配给 C 中的变量(来自函数)?

c++ - 从构造函数主体调用另一个构造函数

c++ - std 容器在多线程环境中是否总是抛出异常?

c - 用 C 拆分字符串