c++ - Forward declaration causing problems in header file -
i'm trying larn link lists , nodes , don't understand error within node struct. code worked fine, without forwards declaration in header
#ifndef sentence_h #define sentence_h #include"word.h" class sentence{ public: struct node{ word data; node * next; }; //etc #endif // sentence_h but had add together function prototypes required me alter
#ifndef sentence_h #define sentence_h class sentence; #include"paragraph.h" #include"word.h" class sentence{ public: struct node{ word data; node * next; }; //etc, etc now when seek compile error: field 'data' has incomplete type. if comment out struct works fine. doing wrong? believe right way create node not? in sentence linked list of nodes words in them. 'data' word, , next pointer node. word type should acceptable because of include statement, have no problem function prototype "word first();" in etc part of code, why tell me 'data' has incomplete type?
my crystal ball tells me problem has nil forwards declaration , circular header inclusion. same ball tells me @ point word.h began include sentence.h straight or indirectly. now, since sentence.h includes word.h well, produced circular inclusion loop.
circular inclusion not ever accomplish anything, besides weird "unexplainable" compilation errors.
c++ linked-list nodes
No comments:
Post a Comment