|
From: <Wal...@va...> - 2002-05-20 17:20:25
|
Need a little help with friend and templates
This code compiles with errors using Borlands 4.52
Here is my class:
template <class le>
class LinkedList
{
private:
class Node
{
public:
le data;
Node *next;
Node(le dataValue)
{
data=dataValue;
next=0;
}
}; // end of Node class
typedef Node * NodePointer;
NodePointer first,newPtr,next;
int numNodes;
public:
LinkedList()
{
first=0;
numNodes=0;
}
~LinkedList(); //destructor
LinkedList(LinkedList<le>&); //assignment constructor
LinkedList(int,le); //next constructor
void Insert(le &dataVal, int position);
void DeletePos(int);
void InsertFront(le &value); //Inserts value into front of
the list
void InsertBack(int &value); //Inserts value into back of
the list
void InsertMid(int n, le &value, int pos); //Inserts n
nodes with value into pos
NodePointer getTail();
void RemoveFront();
void RemoveBack();
void RemoveVal(le &value);
LinkedList<le> getFront();
LinkedList<le> getBack();
le getData(int pos);
int getnumnodes();
void Erase(int, int); //range between pos and pos
NodePointer Append(NodePointer);
int len();
int lenAux(NodePointer);
void swapList(LinkedList &);
bool Search(int);
bool SearchAux(NodePointer, le);
//recursive search for datatype
void Append(LinkedList &);
friend ostream& operator<<(ostream &out,
LinkedList<le> &l);
}; // --- end of LinkedList class
int main()
{
LinkedList<int> L1(5,5),L2(5,6);
cout<<"1 L1 is "<<L1<<endl;
cout<<"2 L2 is "<<L2<<endl;
.
.
.
warning: friend declaration `class ostream & operator <<(ostream &,
LinkedList<le> &)'
warning: declares a non-template function
warning: (if this is not what you intended, make sure
warning: the function template has already been declared,
warning: and add <> after the function name here)
warning: -Wno-non-template-friend disables this warning.
Compiler and linker output:
undefined reference to `operator<<(ostream &, LinkedList<int> &)'
Walt
"This e-mail message is intended only for the use of the named
recipient(s).
The information contained therein may be confidential or privileged, and
its
disclosure or reproduction is strictly prohibited. If you are not the named
recipient, please return it immediately to its sender at the above address
and destroy it."
|