I have a class called OrderedList in a namespace MYLIB. In it I have a nested class called iterator which will be used as an iterator for the OrderedList class.
Following is the snippet of my code where I create OrderedList and iterator classes:
template<class T>
class OrderedList
{
private:
ListNode<T>* head;
ListNode<T>* tail;
int total;
public:
OrderedList(T[],int);
~OrderedList();
void insert(const T&);
void sort(int);
void output();
class iterator
{
private:
ListNode<T>* curr;
int current;
OrderedList& order;
public:
iterator(OrderedList& ord, bool is_end)
{
this->order = ord; //problem is here
if(is_end == false)
{...
Snippet of my main function:
int main()
{
int one[5] = {9,7,5,4,1};
MYLIB::OrderedList<int> odd(one,5);
odd.output();
MYLIB::OrderedList<int>::iterator starter(odd,false);
When I compile it gives me the following error:
OrderedList.cpp: In instantiation of ‘MYLIB::OrderedList<T>::iterator::iterator(MYLIB::OrderedList<T>&, bool) [with T = int]’:
OrderedList.cpp:215:53: required from here
OrderedList.cpp:47:6: error: uninitialized reference member ‘MYLIB::OrderedList<int>::iterator::order’ [-fpermissive]
iterator(OrderedList& ord, bool is_end)
^
// line XXXX HERE. Make it as easy as possible for people to test your problem and produce a solution.