我正在尝试用C ++实现单链表列表。我不知道我的内容是否正确地组织在每个文件中。我有LList.h,LList.cpp和test.cpp。我认为错误与我的默认构造函数有关。我在XCode上的Mac上不断收到3个编译器错误。这是我的代码
// LList.h:
#ifndef LList_LList_h
#define LList_LList_h
struct Node {
char info;
Node *next;
};
class LList {
private:
Node *head;
Node *cons(char ch, Node *p);
Node *deleteAll(char ch, Node *p);
Node * insert(char ch, Node *p);
public:
LList();
~LList();
LList(LList &list);
bool isEmpty() const;
void print() const;
};
#endif
// LList.cpp
#include <iostream>
#include "LList.h"
#ifndef LList_LList_h
#define LList_LList_h
LList::LList() :list(nullptr) {
// no body
}
Node LList::cons(char ch, Node *p) {
Node *q = new Node;
q->info = ch;
q->next = p;
return q;
}
Node *LList::deleteAll(char ch, Node *p) {
if (p == nullptr || ch < p->info) {
return p;
}
if (ch == p->info) {
Node *discard = p;
p = p->next;
delete discard;
return deleteAll(ch, p->next);
} else {
return deleteAll(ch, p->next);
}
}
Node *LList::insert(char ch, Node *p) {
if (p == nullptr || ch <= p->info) {
return cons(ch,p);
}
Node *q = p;
Node *r = q->next;
while (r != nullptr && ch > r->info) {
q=r;
r=r->next;
}
q->next = cons(ch,p);
return p;
}
bool LList::isEmpty() const{
return (head == nullptr);
}
void LList::print (Node *p) {
while (p != nullptr) {
std::cout << p->info << " ";
p = p->next;
}
}
#endif
_______________
//test.cpp
#include "LList.h"
int main() {
LList list;
return 0;
}
请帮忙!! 我的错误说:
Undefined symbols for architecture x86_64:
"LList::LList()", referenced from:
_main in test.o
"LList::~LList()", referenced from:
_main in test.o
ld: symbol(s) not found for architecture x86_64