【发布时间】:2016-04-09 21:53:49
【问题描述】:
这是我的头文件
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
#include <string>
using namespace std;
class Node
{
friend class LinkedList;
public:
Node(string& name, int num) :studentName(name), RUID(num)
{
this->next = NULL;
}
private:
string studentName;
int RUID;
Node *next;
};
class LinkedList
{
public:
LinkedList();
~LinkedList();
LinkedList& operator+(LinkedList &i);
//LinkedList operator=();
void makeLists(int n);
void addNode(LinkedList &i);
void removeNode();
void printList();
void printElement();
void sortList();
private:
Node *head;
Node *tail;
int size;
};
#endif
...这是我的 operator+ 函数
LinkedList& LinkedList::operator+(LinkedList &i)
{
LinkedList tohma;
tohma = *this;
tohma += i;
return tohma;
}
我收到 += 运算符的错误消息,但我不知道应该如何做不同的事情。我觉得我很接近,但也许我犯了一个逻辑错误?
我们将不胜感激任何和所有的帮助
【问题讨论】:
-
它是
operator+,而不是+=(甚至没有定义),它通过引用返回一个本地 - 错误。按值返回。 -
抱歉,我的意思是“tohma += i”处有一条错误消息。我的坏
标签: c++ linked-list operator-overloading singly-linked-list