Linked List Code
I'm having trouble with this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <iostream>
#include <cstdlib>
using namespace std;
#ifndef Null
#define Null 0
#endif
class Node
{
public:
int data;
Node *link;
};
class LList
{
public:
LList ();
~LList();
void create();
void display();
Node* getNode();
void append(Node* NewNode);
void insert(Node *NewNode, int pos);
void rtraverse();
void deleteNode(int deletePos);
private:
Node *Head, *Tail;
void recursiveTraverse (Node *tmp)
{
if (tmp == Null)
{
return;
}
cout << tmp->data << "\t";
recursiveTraverse (tmp->link);
}
};
LList :: ~LList ()
{
Node *Temp;
while (Head != Null)
{
Temp = Head;
Head = Head->link;
delete Temp;
}
}
void LList :: create ()
{
char ans;
Node *NewNode;
while (1)
{
cout << "Any more nodes to be added (Y/N):";
cin >> ans;
if (ans == 'n' || ans == 'N')
{
break;
}
NewNode = getNode ();
append(NewNode);
}
}
void LList :: append(Node* NewNode)
{
if (Head == Null)
{
Head = NewNode;
Tail = NewNode;
}
else
{
Tail->link = NewNode;
Tail = NewNode;
}
}
Node* LList :: getNode()
{
Node *Newnode;
Newnode = new Node;
cin >> Newnode->data;
Newnode->link = Null;
return (Newnode);
}
void LList :: display()
{
Node *temp = Head;
if (temp == Null)
{
cout << "Empty List";
}
else
{
while(temp != Null)
{
cout << temp->data << "\t";
temp = temp->link;
}
}
cout << endl;
}
int main()
{
LList L1;
L1.create();
L1.display();
return 0;
}
|
I get an error "[Linker error] PATHNAME:(.text+0x1b2): undefined reference to ~LList::LList()' "
Any idea what is going on here... Thanks.
No constructor here.. Thats why...duh !
http://ideone.com/N3EXgIgcc wrote: |
---|
In function `main':
prog.cpp:(.text.startup+0x13): undefined reference to `LList::LList()' |
On line 19 you declare that there exists a default ctor, but where do you define such a thing? Your compiler can't find it because neither can you.
Topic archived. No new replies allowed.