I'm trying to implement a trie and I get the following error:
error: invalid use of void expression
5 | collect(node->next[c], pre.push_back(c), q);
| ^~~~~~~
This is my function:
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);
}
}
This is the only error I get. Everything else work fine.
Any help? Please.
http://www.cplusplus.com/reference/string/string/push_back/
string::push_back returns a Void type (ie, doesn't return) and you are using the return value of this call as an argument here:
collect(node->next[c], pre.push_back(c), q);
I am not sure exactly what you are trying to do, but this is the cause for the error.