我有一个函数可以追溯到导致段错误,但我似乎找不到我做错了什么。我正在尝试使用打印语句来查找 seg 错误发生的位置,但显然该函数运行没有问题 THEN 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 错误在这条线被调用后直接发生,我可能做错了什么?
ps 复制构造函数只是将 queueFront 设置为 NULL 并调用复制函数。