除非我使运算符重载函数const,否则它将不会编译,但是如果我这样做,则LinkedList1的成员变量不会像应有的那样更改。
LinkedList LinkedList::operator+=(const LinkedList& object)
{
Node::data_type temp;
LinkedList n1 = *this;
Node* ptr;
ptr = object.head;
while (ptr != nullptr)
{
temp.set_name(ptr->get_data().get_name());
temp.set_score(ptr->get_data().get_score());
n1.addToTail(temp);
ptr = ptr->get_linkN();
}
return n1;
}
int main()
{
LinkedList firstList;
LinkedList secondList;
initialize(firstList, secondList);
firstList += secondList;
}