I have this code:
Code:
template <class T>
class SortedList
{
private:
struct Node
{
T data;
Node* next;
};
Node* m_head;
Node* m_current;
public:
friend bool operator==<T>(const SortedList<T>& L1, const SortedList<T>& L2);
and i try to use Node in the friend function:
Code:
template <class T>
bool operator==(const SortedList<T>& L1, const SortedList<T>& L2)
{
SortedList<T>::Node* head1 = L1.m_head;
SortedList<T>::Node* head2 = L2.m_head;
while (head1 != NULL && head2 != NULL) {
if (head1->data != head2->data) {
return false;
}
head1 = head1->next;
head2 = head2->next;
}
return (head1 == NULL && head2 == NULL);
}
the compiler (g++) doesn't recognize the type, although i made this function friend... i guess it's template related, but i can't find any info on how to do it with templates...
it just says:
Code:
../sortedlist.h:163: error: ‘head1’ was not declared in this scope
../sortedlist.h:164: error: ‘head2’ was not declared in this scope
anyone?