错误 C2275 RHandle:非法使用此类型作为表达式

error C2275 RHandle: illegal use of this type as an expression

本文关键字:类型 表达式 C2275 RHandle 非法 错误      更新时间:2023-10-16

我收到错误:

C2275 RHandle:非法使用此类型作为表达式

。当我编译这个时:

int main(){
    int i,j;
    float** tree;
    tree = (float**)malloc(15 * sizeof(float*));
    for( i = 0; i < 15; i++) 
        tree[i] = (float*)malloc(2 * sizeof(float));
    for(i = 0; i < 15; i++)
        for( j = 0; j < 2; j++)
            tree[i][j] = 2;
    RHandle h = create_reprVectorsTree(tree, 8, 2); // error at this line
    // ...
}

我的界面看起来像这样:

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 , int *, int);
#ifdef __cplusplus
}
#endif

我遵循了这个问题中的示例。

我正在Visual Studio 2008上编译。

问题出在哪里?

只是一个猜测,但如果它被编译为 C89,你不能像这样在作用域中间声明一个变量。

int main(){
int i,j;
float** tree;
RHandle h;
tree = (float**)malloc(15 * sizeof(float*));
for( i = 0; i < 15; i++) 
    tree[i] = (float*)malloc(2 * sizeof(float));
for(i = 0; i < 15; i++)
    for( j = 0; j < 2; j++)
        tree[i][j] = 2;    
h = create_reprVectorsTree(tree, 8, 2);

你是否开始你的代码

#include "my_header.h"

当然,使用您的接口文件的任何名称?如前所述,编译器无法知道RHandle的含义。

请不要总结代码。错误往往出现在你"知道*是正确的部分,而忽略在摘要之外。

相关文章: