У меня проблемы с созданием функции перегрузки "<<" для моего двусвязного списка. </p>
Вот мой заголовочный файл:
#ifndef SORTEDLIST_H
#define SORTEDLIST_H
#include <iostream>
class SortedList {
private:
typedef struct node {
int data;
node* next;
node* prev;
}*nodePtr;
int theSize;
nodePtr head;
nodePtr tail;
public:
SortedList();
//~SortedList();
void insertItem(int inData);
bool deleteItem(int delData);
friend ostream& operator <<(ostream& ot, const SortedList& sL);
int size() const;
bool empty() const;
};
#endif
Вот мой конструктор:
SortedList::SortedList() {
//Set pointers equal to NULL
head = NULL;
tail = NULL;
theSize = 0;
head = new node; //create new node of 3 parts: head, data and prev
tail = new node; //create new node of 3 parts: head, data and prev
head->next = tail; //next partition points to tail
head->prev = NULL; //not necessary to put in?
tail->prev = head; //prev partition points to head
tail->next = NULL; //not necessary to put in?
/*temp->next = tail; //access the node the temp pointer is pointing to, set the 'next' part equal to tail*/
}
и вот функция перегрузки ostream, которую я не могу заставить работать:
ostream& operator<<(ostream& ot, const SortedList& sL)
{
sL.nodePtr temp;
temp = sL.head->next;
while (temp != sL.tail) {
ot << temp->data << " ";
temp = temp->next;
}
ot << "\n";
}
Мне постоянно говорят, что sL.NodePtr, sL.head, sL.tail недоступны. Я установил его в качестве функции друга, поэтому не уверен почему.