鉴于以下内容: -
#include <stdlib.h>
#include <stdio.h>
#include "SOM.h"
int N = 10;
int FEATURES = 5;
struct _Node{
int x, y;
double w[];
};
struct Node **nodes;
void main(){
init();
}
void init(){
int i, j;
Node tmp;
nodes = malloc(N * sizeof(Node*));
for(i=0; i<N; i++){
nodes[i] = malloc(N * (2*sizeof(int) + FEATURES*sizeof(double)));
for(j=0; j<N; j++){
nodes[i][j]->x = i; //Troublesome line
nodes[i][j]->y = j; //Troublesome line
nodes[i][j]->w = {0.0, 0.1}; //Troublesome line
}
}
}
void clean(){
//
}
标题: -
#ifndef SOM
#define SOM
typedef struct _Node Node;
void init();
void clean();
#endif
我在编译时收到以下内容: -
SOM.c: In function ‘init’:
SOM.c:25:7: error: invalid use of undefined type ‘struct Node’
SOM.c:25:15: error: dereferencing pointer to incomplete type
SOM.c:26:7: error: invalid use of undefined type ‘struct Node’
SOM.c:26:15: error: dereferencing pointer to incomplete type
SOM.c:27:7: error: invalid use of undefined type ‘struct Node’
SOM.c:27:15: error: dereferencing pointer to incomplete type
SOM.c:27:24: error: expected expression before ‘{’ token
然而,我(据我所知)定义了_Node结构,并给它起了假名Node。我想我误解了这个错误。有人能够解释什么是错的。我本身并不是在寻找代码修复,更多的是对我出错的原因的解释。
此致
答案 0 :(得分:7)
这一行错了:
struct Node **nodes;
它必须是:
Node **nodes;
或:
struct _Node **nodes;
但不是两者的混合物,正如你现在所拥有的那样。