鉴于以下情况:-
#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。我想我误解了这个错误。有人能够解释什么是错的。我不是在寻找代码修复本身,而是对我哪里出错的解释。
问候