문제 설명
개체 배열 매개변수‑‑오류: '문자' 필드에 불완전한 유형이 있습니다. (Object array parameter‑‑error: field ‘letters’ has incomplete type)
struct Trie {
Trie letters [27];
bool hasLetter;
bool EOW;
...
}
오류: '문자' 필드에 불완전한 유형이 있습니다.
이 오류가 발생하고 무엇이 잘못되었는지 알아내지 못했습니다. 배열을 사용하여 Trie를 만들려고 하는데 g++ 컴파일러를 사용하고 있습니다. 도움을 주시면 감사하겠습니다.
참조 솔루션
방법 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;
...
}
(by waterhouse、djcouchycouch)