我有一个功能,我追溯到导致seg错误,但我似乎无法找到我做错了什么。我正在尝试使用print语句来查找seg故障发生的位置,但显然函数运行时没有问题然后出现seg错误。这是功能:
//note all of the cout statements are executed
template<class Type>
void linkedQueue<Type>::copyQueue(const linkedQueue<Type>& otherQueue)
{
//if the queue is in use, delete its contents
if(!isQueueEmpty())
initializeQueue();
if(otherQueue.isQueueEmpty()) {
queueFront = NULL;
queueRear = NULL;
count = 0;
} else {
queueNodeType<Type> *current, *newNode, *last;
current = otherQueue.queueFront;
queueFront = new queueNodeType<Type>;
queueFront->info = current->info;
queueFront->link = NULL;
last = queueFront;
current = current->link;
while(current != NULL) {
newNode = new queueNodeType<Type>;
newNode->info = current->info;
newNode->link = NULL;
queueRear = newNode;
last->link = newNode;
last = newNode;
cout << current->info << endl;
current = current->link;
}
cout << "here?\n";
count = otherQueue.count;
}
cout << "ended\n";
}
这个函数在main中调用:
linkedQueue<int> queue4(queue3);
在调用此行之后直接发生了seg错误,我可能做错了什么?
P.S。复制构造函数只是将queueFront设置为NULL并调用复制函数。