当我尝试重载复制构造函数时,它给出了以下错误代码 当我试图重载<<时,我遇到了类似的错误消息操作
我通过定义内部标题
来修复它然而,这次同样的伎俩不起作用..
如何修复此问题以及导致此错误消息的原因是什么?
这是我的复制构造函数定义
template <class ItemType>
void List342<ItemType>::operator=(List342 &source)
{
Node *sNode, *dNode, *insNode;
if (this == &source) return;
this->Clear();
if (source.head == NULL)
{
return;
}
dNode = new Node;
dNode->value = (source.head)->value;
this->head = dNode;
sNode = (source.head)->next;
while (sNode != NULL)
{
insNode = new Node;
insNode->value = sNode->value;
dNode->next = insNode;
dNode = dNode->next;
sNode = sNode->next;
}
}
这是我的头文件。
#ifndef LIST342_H_
#define LIST342_H_
#include <iostream>
#include <string>
using namespace std;
template <class ItemType>
class List342 {
friend ostream& operator<<(ostream &outStream, const List342 &list)
{
Node *pNode;
pNode = list.head;
while (pNode != NULL)
{
outStream << *pNode->data;
pNode = pNode->next;
}
return outStream;
}
public:
List342();
List342(List342<ItemType> &);
~List342();
bool BuildList(string FileName);
bool Insert(ItemType *obj);
bool Remove(ItemType target, ItemType &result);//check
bool Peek(ItemType target, ItemType &result);//check
bool isEmpty();
void ClearList();
bool Merge(List342 &list1, List342 &list2);
List342 operator+(const List342 &list) const;
List342 operator+=(const List342 &list);
bool operator==(const List342 &list) const;
bool operator!=(const List342 &list) const;
void operator=(List342 &);
private:
struct Node {
ItemType *data;
Node *next;
};
Node *head;
};
#endif /* LIST342_H_ */