Problem with Code – Dynamic Array and Overloading an Output Operator

  c++

I’m having an issue with my code for one of my classes, the assignment is to use this code to derive UlistType (unordered list) and OListType (ordered list) from the abstract class ListType.h (below) and should print both to the screen, any help at all would be greatly appreciated!

header file:

#define LISTTYPE_H_INCLUDED
#include <iostream>

class ListType {
public:
 ListType(size_t=10);
 virtual ~ListType();
 virtual bool insert(int)=0;
 virtual bool erase();
 virtual bool erase(int)=0;
 virtual bool find(int) const=0;
 size_t size() const;
 bool empty() const;
 bool full() const;
 friend std::ostream& operator << (std::ostream&, const ListType&);
protected:
 int *items;
 size_t capacity;
 size_t count;
};
#endif

.cpp file:

#include "ListType.h"

ListType::ListType (size_t a) {
 capacity = a;
 count = 0;
 items = new int [capacity];
}

ListType::~ListType() {
 delete [] items;
}

bool ListType::erase() {
 count = 0;
 return 0;
}

size_t ListType::size() const {
 return (count);
}

bool ListType::empty() const {
 return (count == 0);
}

bool ListType::full() const {
 return (count == capacity);
}

std::ostream& operator << (std::ostream& out, const ListType& list1) {
 int a = 0;
 out << list1[a] << ", " ;
 return out;
}


Assignment in more detail:
  [1]: https://i.stack.imgur.com/Ql5fb.jpg

Source: Windows Questions C++

LEAVE A COMMENT