SingleList.h
#include "ListBase.h"
#include "DataNode.h"
#include "SingleListIterator.h"
namespace list
{
class SingleListIterator;
class SingleList : public ListBase
{
private:
DataNode *head;
DataNode *tail;
public:
SingleList();
SingleList(const SingleList &obj);
~SingleList();
void Flush(); //deletes all elements in the list
void PushInFront(const int data); // **
void Append(const int data); // **
void DeleteLast();
void DeleteFirst();
int Delete(const int& data); // ** remove the first occurrence of data and return 1 otherwise 0
const int& GetFirst() const; // **
int& GetFirst(); // **
const int& GetLast() const; // **
int& GetLast(); // **
void PrintList() const;
const int IsEmpty() const;
// SingleList<T> &operator=(const SingleList<T>& obj) (**)
// const int operator==(const SingleList<T> &obj) const (**)
// const int operator!=(const SingleList<T> &obj) const (**)
// SingleList<T>& operator+(const SingleList<T> &obj) (**) // concatenates two lists
// operator int() // returns list size (**)
friend class SingleListIterator; // ** ASK Changd it from Iterator
};
SingleListIterator.h
#include "Iterator.h"
#include "SingleList.h"
namespace list
{
class SingleList;
class SingleListIterator: public Iterator
{
public:
// error here --> Forward declaration of 'const struct list::SingleList'
SingleListIterator(const SingleList &list); // **
SingleListIterator(const SingleListIterator &obj); // **
virtual const int Current() const; // **
virtual void Succ();
virtual const int Terminate() const;
virtual void rewind();
// T &operator++(int) (**)
// SingleListIterator<T>& operator=(const SingleListIterator<T>&obj) (**)
};
// error here --> Invalid use of incomplete type 'list::SingleList'
SingleListIterator::SingleListIterator(const SingleList &list) : Iterator(list.head)
{
}
Errors indicated in code
Also what can I do in a case like this where there is mutual coupling between two header files ?????
Thaaaaanks
You use forward declarations, but you anyway include the
.hfiles recursively. The point of the forward declarations is that you don’t need to include the headers of theforward declared class, thereby breaking the mutual dependency.
Also it should be enough to use a forward declaration for one of the classes, not for both of them.
I would suggest the following structure:
SingleListIterator.h:
SingleList.h:
SingleListIterator.cpp:
SingleList.h:
This way there are no files that mutually include each other and all types are completely known in the implementation (.cpp) files.