1

Heres a simple question, I'm implementing suffix array but I'm stuck here:

#define SIZE 150

struct node{
     transition *next[SIZE];   //error here
};

struct transition{
    int left, right;
    node *suffix_link;
};

This code won't compile, there's an error in the third line, can anyone help me plz? thanks :D

UPDATE: My bad I forgot to include the first line, sorry it's my first question here :P

Frank
  • 2,738
  • 19
  • 30
maurizzzio
  • 39
  • 4

3 Answers3

8

You need to forward declare transition:

struct transition;  // <-- forward declaration

struct node{
     transition *next[SIZE];
};

struct transition{
    int left, right;
    node *suffix_link;
};
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
1

Use a forward declaration:

struct transition;

struct node
{
    transition *next[SIZE];
};

struct transition
{
   int left, right;
   node *suffix_link;
};
Frank
  • 2,738
  • 19
  • 30
1

Why forward declaration?

Because, the complete defintion of transition is not yet known to the compiler when you use it.

The same is not required for node because it's already been defined when you use it in transition.

P.P
  • 117,907
  • 20
  • 175
  • 238