#ifndef TRIEAPI
#define TRIEAPI
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;
typedef struct NodeStruct
{
bool validNgram = false;
unordered_map<string, struct NodeStruct> children;
struct NodeStruct* parent;
string nodeWord;
NodeStruct(struct NodeStruct* par, string w) : parent(par), nodeWord(w) {} //constructor (yeah, structs have them too)
NodeStruct() {}
}Node;
void addNgramTrie(Node* root, string ngram);
void findNgramsTrie(Node* root, string query);
void splitText(string query, vector<string> &words);
void deleteNgramTrie(Node* root, string ngram);
void recursiveParentDeletion(Node* node, Node *root);
#endif // TRIEAPI
當我嘗試編譯程序我得到關於所述pair.h該頭文件中的錯誤(以g ++編譯5.4 C++ 11):C++:pair.h編譯器錯誤 - 對具有不完全的類型
trie.h:14:46: required from here
/usr/include/c++/5/bits/stl_pair.h:102:11: error: ‘std::pair<_T1, _T2>::second’ has incomplete type
_T2 second; /// @c second is a copy of the second object
^
In file included from trie.cpp:10:0:
trie.h:11:16: note: forward declaration of ‘struct NodeStruct’
typedef struct NodeStruct
我不明白我錯在哪裏。
*「當我嘗試編譯程序時」* - 什麼程序?我沒有看到一個程序。 – IInspectable
@iinspectable,你看到了什麼?錯誤? :-P – WhiZTiM
@JimS,那些'typedef'在C++中是沒用的,只是給代碼添加了混亂。您不需要「Eloborated類型說明符」 – WhiZTiM