Here is my code:
slist.hpp
#ifndef SLIST_HPP
#define SLIST_HPP
#include"slist.h"
#include"slistiterator.h"
#include"slistiterator.hpp"
template<typename generic>
SList<generic>::SList()
{
m_size = 0;
m_front = NULL;
}
template<typename generic>
SList<generic>::SList(const SList<generic>& s) : m_front(NULL), m_size(0)
{
*this = s;
}
template<typename generic>
SList<generic>::~SList()
{
clear();
}
template<typename generic>
void SList<generic>::push_front(generic x)
{
SNode<generic>* temp = new SNode<generic>;
temp->b = m_front;
m_front = temp;
m_front->data = x;
m_size++;
}
template<typename generic>
void SList<generic>::pop_front()
{
if(m_front != NULL)
{
SNode<generic>* temp = new SNode<generic>;
temp = m_front; m_front = m_front->b;
delete temp;
m_size--;
}
}
template<typename generic>
void SList<generic>::remove(generic x)
{
if(m_front != NULL)
{
SNode<generic>* temp1 = new SNode<generic>;
SNode<generic>* temp2 = new SNode<generic>;
do
{
temp1 = m_front;
while(temp1 != NULL && temp1->b->data != x)
{
temp1 = temp1->b;
}
if(temp1 != NULL)
{
temp2 = temp1->b->b;
delete temp1->b;
m_size--;
temp1->b = temp2;
}
}while(temp1 != NULL && temp2 != NULL);
}
}
template<typename generic>
generic& SList<generic>::front()
{
if(m_front = NULL)
{
throw out_of_range
(
"There is no data to return"
);
}
return *m_front;
}
template<typename generic>
const generic& SList<generic>::front() const
{
if(m_front = NULL)
{
throw out_of_range
(
"There is no data to return"
);
}
return *m_front;
}
template<typename generic>
void SList<generic>::clear()
{
while(m_front != NULL)
{
pop_front();
}
}
template<typename generic>
unsigned int SList<generic>::size() const
{
return m_size;
}
template<typename generic>
bool SList<generic>::empty() const
{
return (m_front == NULL);
}
template<typename generic>
Iterator SList<generic>::begin() const
{
return Iterator(m_front);
}
template<typename generic>
Iterator SList<generic>::end() const
{
return Iterator();
}
template<typename generic>
SList<generic>& SList<generic>::operator=(const SList<generic>& s)
{
clear();
if(!s.empty())
{
m_front = new SNode<generic>;
SNode<generic>* temp = m_front;
for(Iterator i = s.begin(); i != s.end(); m_size++, temp = temp->b)
{
temp->data = *i;
i++ != s.end() ? temp->b = new SNode<generic> : temp->b = NULL;
}
}
return *this;
}
#endif
slist.h
/*
Class: SList
A singly-linked list container.
Constructor: SList()
Initializes the size to 0 and the front to null.
Constructor: SList(const SList& s)
Clears the contents of the list and then creates a duplicate of s.
Parameters:
s - The list to be copied.
Destructor: ~SList()
Deletes the entire contents of the list.
Function: void push_front(generic x)
Inserts the data item x to the front of the list.
Parameters:
x - The data item to be inserted.
Function: void pop_front()
Removes a data item from the front of the list. If there are no items to
remove, then the function does nothing.
Function: void remove(generic x)
Removes all instances of x from the list. If there are no data items
containing x to remove, then the function does nothing.
Parameters:
x - The data item to be removed.
Function: generic& front()
Retreives a writeable reference to the data item at the front of the list. If
the list is empty then a standard out_of_range exception is thrown.
Returns:
A writeable reference to the list's front data.
Function: const generic& front() const
Retreives a read-only reference to the data item at the front of the list. If
the list is empty then a standard out_of_range exception is thrown.
Returns:
A read-only reference to the list's front data.
Function: void clear()
Deletes the entire contents of the list and sets size back to 0.
Function: unsigned int size() const
Reports the number of data items in the list.
Returns:
The number of items stored in the list.
Function: bool empty() const
Reports if the list is holding data or is not holding any data.
Returns:
True if the list has no data and false if it has data.
Function: Iterator begin() const
Places an iterator at the front of the list.
Returns:
An iterator positioned at the front of the list.
Function: Iterator end() const
Places an iterator at the back of the list.
Returns:
An iterator positioned at the back of the list.
Operator: SList& operator=(const SList& s)
Clears the contents of the list and then creates a duplicate of s.
Parameters:
s - The list to be replicated.
Returns:
A reference to the newly cloned list.
*/
#ifndef SLIST_H
#define SLIST_H
#include"snode.h"
#include"slistiterator.h"
#include<stdexcept>
using std::out_of_range;
template<typename generic>
class SList
{
public:
SList();
SList(const SList& s);
~SList();
void push_front(generic x);
void pop_front();
void remove(generic x);
generic& front();
const generic& front() const;
void clear();
unsigned int size() const;
bool empty() const;
typedef SListIterator<generic> Iterator;
Iterator begin() const;
Iterator end() const;
SList& operator=(const SList& s);
private:
unsigned int m_size;
SNode<generic>* m_front;
};
#include"slist.hpp"
#endif
This should be all of the relevant code, but If you need more just say so. Anyway the error is in slist.hpp. It occurs at the two functions that return Iterators, lines 121 and 127.