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. 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" '.
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]. So map<char, type_node>
is an error and consequently the alias is also an error.
In C++ all structs are implicitly typedef'd[2]. Your structure can be simplified to:
struct node
{
int data;
node * next;
};
Links:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.