【发布时间】:2020-01-25 23:53:50
【问题描述】:
我有一个作业问题,要求我重载 == 运算符来比较两个链表。我需要在递归中做到这一点。
这是我的 .h 文件
class LList {
public:
friend bool operator == (const LList& lfSide, const LList& rtSide);
private:
struct Node {
int item;
Node* next;
};
friend bool operator == (const LList& lfSide, Node* headlf, const LList& rtSide, Node* headrt);
Node* head;
}
我尝试使用辅助函数来进行递归,但它仍然给出错误说节点未定义。
friend bool operator == (const LList& lfSide, Node* headlf, const LList& rtSide, Node* headrt);
谁能帮我解决这个问题?
【问题讨论】:
-
您希望如何使用 4 个操作数调用
operator==?您可能应该将其设为非运算符函数。
标签: c++ recursion linked-list overloading friend