C++ Object Object=*此seg错误(C+;+;)

C++ Object Object=*此seg错误(C+;+;),c++,operator-overloading,this,C++,Operator Overloading,This,我在以下代码段上出现了分段错误: main.cpp List list; Movie *m = new Movie(); list+m; //For testing the operator + 编辑:包含所有功能的完整列表.cpp #include "List.h" using namespace std; List::List() : head(0),tail(0),size(0) { } List::~List() { Node *current = head; whil

我在以下代码段上出现了分段错误:

main.cpp

List list;
Movie *m = new Movie();
list+m; //For testing the operator +
编辑:包含所有功能的完整列表.cpp

#include "List.h"


using namespace std;



List::List() : head(0),tail(0),size(0) { }

List::~List() 
{
Node *current = head;
while( current != 0 ) {
    Node* next = current->getNext();
    delete current;
    current = next;
}

head = 0;
}

void List::addMovie(Movie *movie)
{
Node *curNode = new Node(movie);

if(head == NULL)
{
    head = curNode;
    tail = curNode;
    curNode->setNext(NULL);
    curNode->setPrevious(NULL);

}

else
{
    curNode->setNext(NULL);
    tail->setNext(curNode);
    curNode->setPrevious(tail);
    tail = curNode;
}

size++;

} 

Node *List::first()
{
return head;
}

Node *List::last()
{
return tail;
}

void List::addMovie(List & list)
{

Node *curNode = list.first();

while(curNode)
{
    addMovie(curNode->getContent());
    curNode = curNode->getNext();
}

}

void List::removeMovie(Movie *movie)
{
if(size == 0) return;
bool found = false;

Node *curNode = head;

while(curNode)
{
    if(curNode->getContent()->getTitle().compare(movie->getTitle()) == 0)
    {
        found = true;
        break;
    }

    curNode = curNode->getNext();
}

if(!found) return;

if(curNode == head && curNode == tail)
{
    head = NULL;
    tail = NULL;
    delete curNode;
    return;
}

if(curNode == head && curNode != tail)
{
    head = curNode->getNext();
    curNode->getNext()->setPrevious(NULL);
    delete curNode;
    return;
}

if(curNode != head && curNode == tail)
{
    tail = curNode->getPrevious();
    curNode->getPrevious()->setNext(NULL);
    delete curNode;
    return;
}

if(curNode != head && curNode != tail)
{
    curNode->getPrevious()->setNext(curNode->getNext());
    curNode->getNext()->setPrevious(curNode->getPrevious());
    delete curNode;
    return;
}


size--;

}
void List::removeMovie(List &list)
{
Node *curNode = list.first();

while(curNode)
{
    removeMovie(curNode->getContent());
    curNode = curNode->getNext();
}
}
int List::getSize()
{
return size;
} 


Movie *List::findMovie(string title)
{
Node *curNode = head;

while(curNode)
{
    if(title.compare(curNode->getContent()->getTitle()) == 0) return curNode->getContent();
    curNode = curNode->getNext();
}

return NULL;
}
void List::clean()
{

head = tail = NULL;
size = 0;
}

void List::operator =(const List& list)
{

head = list.head;
tail = list.tail;
size = list.size;

}

void List::operator +=(Movie *movie)
{
addMovie(movie);
}

void List::operator +=(const List& list)
{
Node *curNode = list.head;

while(curNode)
{
    addMovie(curNode->getContent());
    curNode = curNode->getNext();
}
}

List List::operator +(Movie *m)
{
 cout << "ok" << endl;
    List list = *this;
     cout << "ok" << endl;
    //list += m;
    //Node *f = list.first();
    /*while(f)
    {
        cout << f->getContent()->getTitle() << endl;
        f = f->getNext();
    }*/

    //return list;
    //Crashing after this
}

List List::operator +(const List& list)
{
 List tmp = *this;
 tmp.size++;

 return tmp;
}
#包括“List.h”
使用名称空间std;
List::List():头(0),尾(0),大小(0){}
列表::~List()
{
节点*电流=头部;
while(当前!=0){
Node*next=current->getNext();
删除当前文件;
当前=下一个;
}
水头=0;
}
无效列表::添加电影(电影*电影)
{
节点*curNode=新节点(电影);
if(head==NULL)
{
头部=颈淋巴结;
tail=curNode;
curNode->setNext(空);
curNode->setPrevious(空);
}
其他的
{
curNode->setNext(空);
tail->setNext(curNode);
curNode->setPrevious(尾部);
tail=curNode;
}
大小++;
} 
节点*列表::第一个()
{
回流头;
}
节点*列表::last()
{
返回尾;
}
无效列表::添加电影(列表和列表)
{
Node*curNode=list.first();
while(curNode)
{
添加电影(curNode->getContent());
curNode=curNode->getNext();
}
}
无效列表::移除电影(电影*电影)
{
如果(大小==0)返回;
bool-found=false;
节点*curNode=头部;
while(curNode)
{
如果(curNode->getContent()->getTitle().compare(movie->getTitle())==0)
{
发现=真;
打破
}
curNode=curNode->getNext();
}
如果(!发现)返回;
if(curNode==head&&curNode==tail)
{
head=NULL;
tail=NULL;
删除curNode;
返回;
}
如果(curNode==头部和&curNode!=尾部)
{
head=curNode->getNext();
curNode->getNext()->setPrevious(NULL);
删除curNode;
返回;
}
如果(curNode!=头部和&curNode==尾部)
{
tail=curNode->getPrevious();
curNode->getPrevious()->setNext(NULL);
删除curNode;
返回;
}
if(curNode!=头部和&curNode!=尾部)
{
curNode->getPrevious()->setNext(curNode->getNext());
curNode->getNext()->setPrevious(curNode->getPrevious());
删除curNode;
返回;
}
大小--;
}
无效列表::移除电影(列表和列表)
{
Node*curNode=list.first();
while(curNode)
{
移除电影(curNode->getContent());
curNode=curNode->getNext();
}
}
int List::getSize()
{
返回大小;
} 
电影*列表::findMovie(字符串标题)
{
节点*curNode=头部;
while(curNode)
{
if(title.compare(curNode->getContent()->getTitle())==0)返回curNode->getContent();
curNode=curNode->getNext();
}
返回NULL;
}
void List::clean()
{
头=尾=空;
尺寸=0;
}
无效列表::运算符=(常量列表和列表)
{
head=list.head;
tail=list.tail;
size=list.size;
}
无效列表::运算符+=(电影*电影)
{
addMovie(电影);
}
无效列表::运算符+=(常量列表和列表)
{
Node*curNode=list.head;
while(curNode)
{
添加电影(curNode->getContent());
curNode=curNode->getNext();
}
}
列表::运算符+(电影*m)
{

不能用运算符编辑帖子或在调试器下运行帖子,获取错误发生的确切位置。
cout
被缓冲,某些输出可能永远不会产生错误。是否存在列表的析构函数?这显然不是您的代码。帖子a。您还需要显示副本构造函数和
List
的定义。真的吗如果你发布给出问题的确切程序,他的问题会更简单