whats wrong with my linklist? Small code, hopefully easy fix :)

Just barely started coding up LinkedList.h from my textbook as we are supposed to add some functions. So that I dont end up with a complete mess I've been running debugger every so often, and currently the damn thing is giving me errors that I just dont see :(.

it says my last bracket " };" on my linkedlist class is:
"missing ';' before identifier LinkedList
missing type specifier -int assumed. C++ does not support default int.

HELP and thank you :)

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
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <stdexcept>
using namespace std;

template<typename T>
class Node
{
public:
	T element; //element contained in the node
	Node<T> *next; //pointer to the next node

	Node() //no arg constructor
	{
		next = NULL;
	}
	Node(T element) //constructor
	{
		this->element = element;
		next = NULL;
	}
};

template<typename T>
class Iterator : public std::iterator<std::forward_iterator_tag, T>
{
public:
	Iterator(Node<T> *p)
	{
		current = p;
	};
	Iterator operator++()
	{
		current = current-> next;
		return *this;
	}
	T &operator*()
	{
		return current -> element;
	}
	bool operator==(const Iterator<T> &iterator)
	{
		return current == iterator.current;
	}
	bool operator !=(const Iterator<T> &iterator)
	{
		return current != iterator.current;
	}
private:
	Node<T> *current;
};

template<typename T>
Class LinkedList
{
public:
	LinkedList();
	LinkedList(LinkedList<T> &list);
	~LinkedList();
	void addFirst(T element);
	void addLast(T element);
	T getFirst() const;
	T getLast() const;
	T removeFirst() throw (runtime_error);
	T removeLast();
	void add(T element);
	void add(int index, T element);
	void clear();
	bool contains(T element) const;
	T get(int index) const;
	int indexOf(T element) const;
	void remove(T element);
	int getSize() const;
	T removeAt(int index);
	T set(int index, T element);

	Iterator<T> begin()
	{
		return Iterator<T>(head);
	};

	Iterator<T> end()
	{
		return Iterator<T>(tail->next);
	};

private:
	Node<T> *head, *tail;
	int size;
};



#endif 


and so far all my main is:

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <string>
#include "LinkedList.h"
using namespace std;

int main()
{
	return 0;
}
I do not see where header <iterator> is included.
row 31: remove ;
also in rows 80 and 85

EDIT: Uhm.. never mind
Last edited on
Your template class is not implemented yet, so you will get all kinds of compile time errors.

What do I mean? Well for instance, void add(T element);, this is a declaration that has no implementation (at least not posted).
See below.
Last edited on
line 31 should not have a semicolon.

Neither shoud 80 or 85.
Last edited on
@anmjc ,

He need not implement its template class because it is not used.
Yes you are correct, I overlooked (thought it was instantiated in main).

Class LinkedList - Should be lowercase class LinkedList.

As well as the include vlad has already pointed out.
Last edited on
k i've added a ton, and now i'm hitting the problem you guys are referring to, sadly I have no idea what it means:
"see reference to class template instantiation 'LinkedList<T>' being compiled"

getting lots of random snags with this and no actual "errors" but it wont compile, under the gun getting this done fast as i can HELP :(
Are you trying to instantiate the LinkedList in main now?

e.g.
LinkedList<int> mylist;

If so can you answer these questions.
1> Are your template classes fully implemented?
If yes see 2. If no, comment out all parts you haven't implemented and just get the class to compile (also 2 still applies if you comment parts out).
2> If so, since you are using them in another translation unit (main) then the implementations need to be inside the template's header file (and not mytemplate.cpp source file).

Topic archived. No new replies allowed.