错误解释

CompileError!

编译信息

main.cpp: In function \xe2\x80\x98int main()\xe2\x80\x99:\nmain.cpp:40:56: error: \xe2\x80\x98function\xe2\x80\x99 was not declared in this scope\n 40 | priority_queue<HuffmanNode*, vector<HuffmanNode*>, function<bool(HuffmanNode*, HuffmanNode*)>> pq(\n | ^~~~~~~~\nmain.cpp:6:1: note: \xe2\x80\x98std::function\xe2\x80\x99 is defined in header \xe2\x80\x98<functional>\xe2\x80\x99; did you forget to \xe2\x80\x98#include <functional>\xe2\x80\x99?\n 5 | #include <algorithm>\n +++ |+#include <functional>\n 6 | using namespace std;\nmain.cpp:40:96: error: expression list treated as compound expression in functional cast [-fpermissive]\n 40 | priority_queue<HuffmanNode*, vector<HuffmanNode*>, function<bool(HuffmanNode*, HuffmanNode*)>> pq(\n | ^\nmain.cpp:40:97: error: template argument 3 is invalid\n 40 | priority_queue<HuffmanNode*, vector<HuffmanNode*>, function<bool(HuffmanNode*, HuffmanNode*)>> pq(\n | ^~\nmain.cpp:42:5: error: invalid user-defined conversion from \xe2\x80\x98main()::<lambda(HuffmanNode*, HuffmanNode*)>\xe2\x80\x99 to \xe2\x80\x98int\xe2\x80\x99 [-fpermissive]\n 42 | );\n | ^\nmain.cpp:41:9: note: candidate is: \xe2\x80\x98main()::<lambda(HuffmanNode*, HuffmanNode*)>::operator bool (*)(HuffmanNode*, HuffmanNode*)() const\xe2\x80\x99 (near match)\n 41 | [](HuffmanNode* a, HuffmanNode* b) { return a->weight > b->weight; }\n | ^\nmain.cpp:41:9: note: no known conversion from \xe2\x80\x98bool (*)(HuffmanNode*, HuffmanNode*)\xe2\x80\x99 to \xe2\x80\x98int\xe2\x80\x99\nmain.cpp:47:12: error: request for member \xe2\x80\x98push\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 47 | pq.push(new HuffmanNode(weights[i], i));\n | ^~~~\nmain.cpp:51:15: error: request for member \xe2\x80\x98size\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 51 | while (pq.size() > 1) {\n | ^~~~\nmain.cpp:52:32: error: request for member \xe2\x80\x98top\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 52 | HuffmanNode* left = pq.top(); pq.pop();\n | ^~~\nmain.cpp:52:42: error: request for member \xe2\x80\x98pop\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 52 | HuffmanNode* left = pq.top(); pq.pop();\n | ^~~\nmain.cpp:53:33: error: request for member \xe2\x80\x98top\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 53 | HuffmanNode* right = pq.top(); pq.pop();\n | ^~~\nmain.cpp:53:43: error: request for member \xe2\x80\x98pop\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 53 | HuffmanNode* right = pq.top(); pq.pop();\n | ^~~\nmain.cpp:57:12: error: request for member \xe2\x80\x98push\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 57 | pq.push(parent);\n | ^~~~\nmain.cpp:60:28: error: request for member \xe2\x80\x98top\xe2\x80\x99 in \xe2\x80\x98pq\xe2\x80\x99, which is of non-class type \xe2\x80\x98int\xe2\x80\x99\n 60 | HuffmanNode* root = pq.top();\n | ^~~\n