嵌套类的类型不完整
Incomplete Type of Nested Class
我有一个以下形式的代码:
class Trie{
public:
Trie( ) : root( new TrieNode( ) ){ };
// Inserts a word into the trie.
void insert( std::string word );
// Returns if the word is in the trie.
bool search( std::string word );
// Returns if there is any word in the trie
// that starts with the 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
};
然而,在第三行,Trie(): root( new TrieNode() )
,编译器继续抱怨TrieNode
不完整。我该如何解决它?
谢谢!
在TrieNode
定义之后定义Trie
的构造函数
class Trie::TrieNode{...}
// must be AFTTER the class Trie is fully defined
Trie::Trie( ) : root( new TrieNode( ) ){ };
否则Trie
的构造函数需要TrieNode
的完整定义,因为它需要构造一个新对象,因此您的错误。
相关文章:
- 给定一个C++嵌套的私有结构类型,是否有从文件范围静态函数访问它的策略
- C++从外部类继承的嵌套类;不允许使用不完整的类型
- 嵌套模板函数采用 2 个具有相同内部类型的容器
- Boost.Python :C++模板类型匹配的嵌套命名空间
- 使用"auto"推断嵌套初始值设定项列表的类型
- std::void_t 和嵌套的非类型成员
- 受保护的嵌套结构不能用作派生外部类中的返回类型?
- 用于返回嵌套类类型的作用域解析运算符
- CRTP:为什么获得嵌套类型和派生类的嵌套方法有区别
- C++中匿名类型的嵌套结构
- 是否可以指定 C++20 个模板化 lambda 来推断嵌套在参数中的类型?
- 为什么在VS2015中模板相关的嵌套类型名称中不需要typename关键字?
- 为什么嵌套类型的基类不需要"typename"?
- 使用模板化类型(嵌套模板类)的部分模板专用化
- 声明嵌套在模板参数中的类型的变量?
- CRTP - 嵌套叶类类型的可见性
- C++:在嵌套名称说明符中命名的不完整类型
- 使用MPI/OpenMP的C 程序带有派生数据类型(嵌套类对象)容器
- 无效地使用不完整类型(嵌套类情况)
- 类型嵌套在模板化类中的部分专用化