0

以下を考えると: -

#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 構造を定義し、ノードという仮名を付けました。私はこのエラーを誤解していると思います。誰かが何が間違っているのか説明できますか。私はコードの修正自体を探しているわけではありません。

よろしく

4

1 に答える 1

7

この行は間違っています:

struct Node **nodes;

次のいずれかである必要があります。

Node **nodes;

また:

struct _Node **nodes;

しかし、あなたが現在持っているように、2つの混合物ではありません.

于 2013-06-21T12:25:37.110 に答える