【发布时间】:2019-12-18 14:54:39
【问题描述】:
使用下面的代码创建了一个新的 Xcode cpp 项目,它给了我一个 clang 错误“链接器命令失败,退出代码 1”。
我尝试在现有的 Xcode 项目中运行此项目并成功构建,但是当我在现有项目中执行此操作或创建新项目并复制粘贴此代码时,同样的问题。我还尝试研究有关此错误的其他 StackOverflow 帖子,但似乎没有任何具体方法可以找到解决方案。
#include <iostream>
#include <stdio.h>
using namespace std;
class LList{
private:
//Represents each node in the LL
struct ListNode{
int data;
ListNode* next;
};
typedef struct ListNode* nodePtr;
nodePtr head, current, temp;
public:
LList();
void Insert(int addData) {
nodePtr n = new ListNode;
n->next = NULL;
n->data = addData;
if(head != NULL){
current = head;
while(current->next != NULL){
current = current->next;
}
current->next = n;
}
else{
head = n;
}
};
void Remove(int removeData) {
nodePtr delPtr = NULL;
temp = head;
current = head;
while(current != NULL && current->data != removeData){
temp = current;
current = current->next;
}
if(current == NULL){
cout << removeData << " was not in the list\n";
delete delPtr;
}
else{
delPtr = current;
current = current->next;
temp->next = current;
if(delPtr == head){
head = head->next;
temp = NULL;
}
delete delPtr;
cout << "The value " << removeData << " was deleted\n";
}
};
void PrintList() {
current = head;
while(current != NULL){
cout << current->data << " - ";
current = current->next;
}
cout << "\n";
};
LList::ListNode* middleNode(LList::ListNode* head) {
LList::ListNode* fastPtr = head;
LList::ListNode* slowPtr = head;
while(fastPtr->next != NULL){
fastPtr = fastPtr->next;
if(fastPtr->next != NULL){
fastPtr = fastPtr->next;
}
slowPtr = slowPtr->next;
}
return slowPtr;
};
};
int main() {
LList Aj;
Aj.Insert(5);
Aj.Insert(8);
Aj.Insert(10);
Aj.PrintList();
Aj.Remove(8);
Aj.PrintList();
Aj.Remove(5);
Aj.PrintList();
}
【问题讨论】: