Hello,
I have downloaded source code from the textbook website and have run into these linker errors:
T3Q21_List_Back error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class orderedLinkedListType<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@ std@@AAV01@ABV?$orderedLinkedListType@H@@@Z) referenced in function _main
T3Q21_List_Back fatal error LNK1120: 1 unresolved externals
I have been able to narrow the source of the problem to the ostream operator overloading function because when I remark out the cout statements that output the class object the program compiles fine. But, I don't know what is wrong with the code because every program in this chapter has the same problem. The overload function is below and the main function is below that. I am running VS2003 as my IDE. Any insight to my problem would help me a bunch.
Code:
//Overloading the stream insertion operator
template<class Type>
ostream& operator<<(ostream& osObject, const linkedListType<Type>& list)
{
nodeType<Type> *current; //pointer to traverse the list
current = list.first; //set current so that it points to
//the first node
while(current != NULL) //while more data to print
{
osObject << current->info << " ";
current = current->link;
}
return osObject;
}
Code:
//Program to test various operations on an ordered linked list
#include <iostream>
#include "orderedLinkedList.h"
using namespace std;
int main()
{
orderedLinkedListType<int> list1, list2; //Line 1
int num; //Line 2
cout<<"Line 3: Enter integers ending with -999"
<<endl; //Line 3
cin>>num; //Line 4
while(num != -999) //Line 5
{
list1.insertNode(num); //Line 6
cin>>num; //Line 7
}
cout<<endl; //Line 8
cout<<"Line 9: List 1: "<<list1<<endl; //Line 9
list2 = list1; //test the assignment operator; Line 10
cout<<"Line 11: List 2: "<<list2<<endl; //Line 11
cout<<"Line 12: Enter the number to be "
<<"deleted: "; //Line 12
cin>>num; //Line 13
cout<<endl; //Line 14
list2.deleteNode(num); //Line 15
cout<<"Line 16: After deleting the node, "
<<"List 2: "<<endl<<list2
<<endl; //Line 16
return 0;
}