i have done the
i have overloaded the '<<' operator in the linked class implementation,
and i declared the .cpp file in my main function, but it's not working,
and this error occurs: undefined reference to operator<& list)
this is the declaration of the ostream function in linkedlist.h file:
friend std::ostream& operator<< (std::ostream& os, LinkedList<T>& list);
and this is the implementation of the ostream function:
template <typename T>
std::ostream& operator<< (std::ostream& os, LinkedList<T> list)
{
list.current = list.start;
while(list.current != NULL)
{
os<< list.current->info<<" -> ";
list.current = list.current->next;
}
os<<"NULL"<<endl;
return os;
}
In the main function, I have created a list that has object from
SavingAccount class
LinkedList <SavingAccount> list;
and the error occurs in the main function in this line:
cout << list <<endl;
well.. this is the LinkedList class implementation:
#include "LinkedList.h"
#include "SavingAccount.h"
#include <cstddef>
using namespace std;
template <typename T>
LinkedList<T>::LinkedList()
{
start = NULL;
current = NULL;
}
template <typename T>
LinkedList<T>::~LinkedList()
{
// Add code.
}
template <typename T>
std::ostream& operator<< (std::ostream& os,const LinkedList<T>& list) {
list.current = list.start;
while(list.current != NULL)
{
os<< list.current->info<<" -> ";
list.current = list.current->next;
}
os<<"NULL"<<endl;
return os;
}
i hope you guys can help me with that, your help is much appreciated
No comments:
Post a Comment