我正在尝试实现一个trie,但出现以下错误:
error: invalid use of void expression
5 | collect(node->next[c], pre.push_back(c), q);
| ^~~~~~~
这是我的函数:
void string_map<T>::collect(Node* node, string pre, std::queue<string> q) const {
if (node == nullptr) {return;}
if (node->definition != nullptr) {q.push(pre); }
for (int c = 0; c < 256; c++) {
collect(node->next[c], pre.push_back(c), q);
}
}
这是我得到的唯一错误。其他一切正常。
有什么帮助吗?请。
http://www.cplusplus.com/reference/string/string/push_back/
string::p ush_back 返回一个 Void 类型(即不返回(,并且您在此处使用此调用的返回值作为参数:
collect(node->next[c], pre.push_back(c), q);
我不确定您要做什么,但这是错误的原因。