I'm writing code for a linked list object. The object uses a structure for the nodes called LinkNode. I want to write assignment operators for the LinkNode structure and for pointers to the data type that the LinkList object contains. Here's a little sample of y code:
template <class Type>
struct LinkNode
{
LinkNode<Type> *prev;
Type *dat;
LinkNode<Type> *next;
};
template <class Type>
class LinkList
{
public:
//All kinds of crap
private:
LinkNode<Type> *first;
LinkNode<Type> *current;
LinkNode<Type> *last;
int length;
}
I want to be able to do something like this:
LinkList<int> list;
int *temp;
temp = list;
I want temp to then have the the address of the data in the current node of list. Does that make sense?
I tried writing an operator like this:
template <class Type>
Type *operator = (Type *t, LinkList<Type> &l)
{
t = l.GetData();
return t;
}
//repeat the same thing for LinkNode<Type>*
That code gives me some error about the operator needing to be a "static member function", or something like that. Can you define the assignment operator outside of a class? If so, do I need to make the first parameter a reference (Type* &t)? Thanks for any help.