For some reason every time I try to make an operator function a friend to a class, I always get the error "illegal operator declaration". I have no clue why. I would be more thankful than you would ever believe if you could solve my problem. Here's the code:
Code:
class intarr
{
protected:
struct node
{
int data;
node * next;
};
node * head;
node * current;
public:
intarr() : head(0), current(head) {}
intarr(int *, unsigned int);
node & operator[](unsigned int);
friend node operator=(node &, int); //the problem
unsigned int len;
};
intarr::intarr(int * d, unsigned int l)
{
head = new node;
current = head;
for(unsigned int a = 0; a < l; a++)
{
current->data = d[a];
current->next = new node;
current = current->next;
}
}
intarr::node & intarr::operator[](unsigned int i)
{
current = head;
for (unsigned int a = 0; a < i; a++)
current = current->next;
return *current;
}
intarr::node operator=(intarr::node & n, int num)
{
n.data = num;
return n;
}