-1
 struct Trie {
    Trie letters [27];
    bool hasLetter;
    bool EOW;
    ...
}

error: field ‘letters’ has incomplete type

I am getting this error and have not been about to figure out what's wrong. I am trying to create a Trie using an array and I'm using g++ compiler. Any help is much appreciated.

1 Answers1

1

The compiler won't accept a struct containing instances of itself if they're not pointers. The error you're getting is because the declaration is recursively using itself. (Trie contains an array of Trie, where each element contains an array of Trie, which each also contains an array of Trie, etc, etc)

If you really want to have the struct containing instances of itself, change letters to be an array of pointers to Trie.

struct Trie {
    Trie* letters [27]; // array of pointers to other Trie structs
    bool hasLetter;
    bool EOW;
    ... 
}
djcouchycouch
  • 12,724
  • 13
  • 69
  • 108