Problem with building my own List class

For my class we have to make our own generic template list structure. I made it so that it compiles fine with integers but am having an issue with strings, when it compiles I get the following error:

1
2
3
4
1>c:\users\jeremy\desktop\school related\cse 330 data structures\list\list\main.cpp(118) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1>        could be 'built-in C++ operator==(const char [3], const char [3])'
1>        while trying to match the argument list '(std::string, const char [3])'
1>Build log was saved at "file://c:\Users\Jeremy\Desktop\School Related\CSE 330 Data Structures\List\List\Debug\BuildLog.htm"


This is my list class, which is broken into three classes.
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#ifndef proj_List_H
#define proj_List_H

template <class T>
class ListLink;

template <class T>
class ListIterator;

template <class T>
class List;


template <class T>
class ListLink
{
public:
	
	ListLink(T x);
	
	
private:
	T x;
	ListLink<T> * prev;
	ListLink<T> * next;

	friend class ListIterator<T>;
	friend class List<T>;

};

template <class T>
class ListIterator
{
public:
	typedef ListIterator<T> iterator;
	//constructor
	ListIterator(ListLink<T> * link);
	//operators
	T & operator *();
	void operator=(iterator & right);
	bool operator==(iterator & right);
	bool operator!=(const iterator & right) const;
	iterator operator++();
	iterator operator--();

	

private:
	ListLink<T> * link;

	friend class ListLink<T>;
	friend class List<T>;

};

template <class T>
class List
{
public: 
	typedef ListIterator<T> iterator;
	//constructors
	List();
	~List();
	//member functions
	unsigned int size() const;
	void push_back(const T x);
	T & front();
	T & back();
	void push_front(const T & x);
	void pop_front();
	void pop_back();
	iterator begin();
	iterator end();
	void erase(iterator position);
	void clear();

	

private:
	unsigned int my_size;
	ListLink<T> * firstLink;
	ListLink<T> * lastLink;
	
	friend class ListLink<T>;
	friend class ListIterator<T>;
	
};

template <class T>
ListLink<T>::ListLink(T x) : x(x), prev(0), next(0)
{

}

//iterator class
template <class T>
ListIterator<T>::ListIterator(ListLink<T> * link): link(link) //constructor that takes an integer for the current link
{
}

template <class T>
T & ListIterator<T>::operator *()
{
	return link->x;
}

template <class T>
void ListIterator<T>::operator=(iterator & right) //operator that assigns link to the right.link
{
	link = right.link;
}

template <class T>
bool ListIterator<T>::operator==(iterator & right) //returns true if the the right of the argument is equal to the current link
{
	return link == right.link;
}

template <class T>
bool ListIterator<T>::operator!=(const iterator & right) const //returns true if the the right of the argument is not equal to the current link
{
	return link != right.link;
}

template <class T>
typename ListIterator<T>::iterator ListIterator<T>::operator++()//returns the links next link
{
	link = link->next;
	return *this;
}

template <class T>
typename ListIterator<T>::iterator ListIterator<T>::operator--()//returns the links previous link
{
	link = link->prev;
	return *this;
}

//List class

template <class T>
List<T>::List() : my_size(0), firstLink(0), lastLink(0)
{

}

template <class T>
List<T>::~List() //destructor deletes all the links
{	
}

template <class T>
unsigned int List<T>::size() const
{
	return my_size;
}

template <class T>
void List<T>::push_back(const T x)//accepts a const integer and puts it at the back
{
	ListLink<T> * newLink = new ListLink<T>(x);
	ListLink<T> * tempLink = lastLink;

	if (my_size == 0) //if the list is empty
		push_front(x); 
	else
	{
		lastLink = newLink;
		newLink->prev = tempLink;
		newLink->next = 0;
		++my_size; //increase value of my_size by 1, doesn't do this if size ==0 because push_front will
	}
	

}

template <class T>
T & List<T>::front() //returns the a reference to the firt element in the list
{
	return firstLink->x;
}

template <class T>
T & List<T>::back() //returns the a reference to the last element in the list
{
	return lastLink->x;
}

template <class T>
void List<T>::push_front(const T & x)//accepts a const integer and puts it at the front
{
	ListLink<T> * newLink = new ListLink<T>(x);

	if (my_size == 0) //if the list is still empty
		firstLink = lastLink = newLink;
	else
	{
		firstLink->prev = newLink;
		newLink->next = firstLink;
		firstLink = newLink;
	}
	++my_size; //increments value of my_size by 1
}

template <class T>
void List<T>::pop_front()//deletes the link at the at the beginning 
{
	ListLink<T> * tempLink = firstLink; //saves the first link temporarily
	firstLink = firstLink->next; //sets the firstLink to the next link
	if (firstLink != 0) //as long as firstLink isn't 0 it then sets firstLink's previous link to 0
		firstLink->prev = 0;
	else//or it sets the value of last link to 0 and deletes the temp value
	{	
		lastLink = 0;
		delete tempLink;
	}
	--my_size; //reduces my_size by 1;
}

template <class T>
void List<T>::pop_back()//deletes the link at the end of the list
{
	ListLink<T> * tempLink = lastLink; //saves the last link temporarily
	lastLink = lastLink->prev; //sets the lastLink to the prev link
	if (lastLink != 0) //if the last link isn't equal to 0 it deletes the templink
		delete tempLink;
	else//or it sets the value of last link to 0 
	{	
		lastLink = 0;
	}
	--my_size; //reduces my_size by 1;

}

template <class T>
typename ListIterator<T> List<T>::begin()//returns the iterator of the firstLink
{
	return iterator(firstLink);
}

template <class T>
typename ListIterator<T> List<T>::end() //returns the iterator of lastLink
{
	return iterator(lastLink);
}

template <class T>
void List<T>::erase(iterator position) //function that erases the value at iterator position
{
	if(position.link == firstLink)
		pop_front();
	else if (position.link == lastLink)
		pop_back();
	else
	{
		position.link->next->prev = position.link->prev;
		position.link->prev->next = position.link->next;
		delete position.link;
		--my_size; //reduces my_size by 1;
	}
	

}


template <class T>
void List<T>::clear()
{
	while (my_size > 0) //runs until my_size == 0
	{
		ListLink<T> * tempLink = lastLink; //creates tempLink and sets it equal to the last link
		lastLink = lastLink->prev;	//sets lastLink equal to the preceding link

		delete tempLink;//deletes temp link

		my_size--;//reduces my_size by 1;
	}
}


#endif 


and my test code in my main cpp file
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
#include <iostream>
#include <cassert>
//#include <list>
#include "List.h"

//#define LIST std::list<int>
#define LIST List<int>

#define LIST2 List<std::string>


int main (int argc, const char * argv[])
{


	LIST2 s1;						//test with string instead of int
	assert(s1.size() == 0);			//test the no argument constructor

	s1.push_back("10");				//test the pushback function, s1 = ("A")
	assert(s1.size() == 1);
         assert(s1.front() == "A");


	
	std::cout << "All tests have passed." << std::endl;
	system("pause");
	return 0;
}


It gets the compile error with the last assert where it checks the front value to see if it equals "A". Any help would be appreciated, thank you!
Topic archived. No new replies allowed.