c++ - Incomplete Type of Nested Class -
i have code in following form:
class trie{ public: trie( ) : root( new trienode( ) ){ }; // inserts word trie. void insert( std::string word ); // returns if word in trie. bool search( std::string word ); // returns if there word in trie // starts given prefix. bool startswith( std::string prefix ); private: class trienode; std::unique_ptr<trienode> root; }; class trie::trienode{ public: trienode( ) : eow( false ){ }; trienode* appendchar( char tar ); void end( ); bool isend( ); trienode* getchar( char tar ); int getind( char tar ); private: std::array<std::unique_ptr<trienode>, 26> data; bool eow; // end of word }; however, @ third line, trie(): root( new trienode() ), compiler continue complains trienode incomplete. how can fix it?
thanks!
define trie's constructor after trienode definition
class trie::trienode{...} // must aftter class trie defined trie::trie( ) : root( new trienode( ) ){ }; otherwise constructor of trie needs full definition of trienode, needs construct new object, hence error.
Comments
Post a Comment