Getting an unndefined error on this funcuon

I copied this function from DS Malik textbook.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  template<class Type>
ostream& operator<<(ostream& osObject, 
                   const doublyLinnkedList<Type>& list)
{
    nodeType<Type> *current;
    current = list.first;

    while(current != NULL)
    {
       count<<current->info<<" ";
       current = current->next;
    }
    return osObject;
}

But when I compile I get an unndefined error to this function
in the main function on lines of "cout << list1;
and cout <<list2;
In other words the lists never get printed.
> count<<current->info<<" ";
Do you have a spare 'n' in there?
Here is part of main()
[code]
int main!()
{
doublyLinkedList<int> list1, list2;
int num;
count<<"Enter integers ending with -999"<<endl;
cin >> num;
while(num != -999)
{
list1.insertNode(num);
cin >> num;
}
cout<<endl;
count<<"List1: " <<List1 <<endl;
list2 = List1;
cout<<"List2: " << list2 <<endl;
}
The undefined error only occurs on the lines that should print the list.
Actually you should use osObject on line 10.

By the way: If the operator<<(...) is a friend function, it needs to be defined entirely inside the template class.
int main!()
...
count<<"List1: " <<List1 <<endl;

You're verging on being a troll with your silly typos.

> But when I compile I get an unndefined error to this function
Yeah, and it would also tell you the NAME of the thing that was undefined.
Most commonly, it's an inability to spell correctly.
Topic archived. No new replies allowed.