[英]Self-referential typedef without object or struct
I'm fairly new to c++, and I'm trying to implement a simple trie to store a lexicon of strings, using the std::map or other c++ standard library container classes. 我对C ++还是很陌生,我正在尝试使用std :: map或其他c ++标准库容器类来实现一个简单的trie来存储字符串词典。 What I'd like to be able to do is use something like 我想做的是使用类似
typedef (map<char, type_node>)* type_node;
for which clang++ gives me the error ' use of undeclared identifier "type_node" '. 为此clang ++给我错误'使用未声明的标识符“ type_node”'。
This as opposed to a self-referential structure, such as 这与自我指称结构相反,例如
typedef struct node {
int data;
struct node *next;
} Node;
Which works fine, somehow. 哪个工作正常,以某种方式。
Is it possible to declare self-referential types without using a class or struct? 是否可以在不使用类或结构的情况下声明自引用类型?
Why does the structure work and not the recursive alias type? 为什么结构有效,而不是递归别名类型?
Is there a better way to do this? 有一个更好的方法吗?
You cannot declare containers with incomplete types[1]. 您不能声明类型不完整的容器[1]。 So map<char, type_node>
is an error and consequently the alias is also an error. 所以map<char, type_node>
是一个错误,因此别名也是一个错误。
In C++ all structs are implicitly typedef'd[2]. 在C ++中,所有结构都隐式为typedef'd [2]。 Your structure can be simplified to: 您的结构可以简化为:
struct node
{
int data;
node * next;
};
Links: 链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.