For this assignment I am to overload the operator[] for a mini List class (basically a watered down list class). I can get the random access to the list by doing list[x] and getting the contents of node x. However when doing reassignments such as:
list[x] = 38
(the list is a list of integers)
I get this error on UNIX:
46: non-lvalue in assignment
I'm guessing that means there is no left hand value in the assignment. Here's my overloaded protocol & body.
(its a templated function)
Protocol:
T operator[](int m);
Body:
template <typename T>
T miniList<T>::operator[] (int m)
{
? ? ? ?// Allows random type access to the list much like an array
? ? ? ?dnode<T> *curr = (*this).header;
? ? ? ?T temp;
? ? ? ?for (int i = 0; i <= m; i++)
? ? ? ? curr = curr->next;
? ? ? ?temp = curr->nodeValue;
? ? ? ?return temp;
}
So I'm returning the type of data thats held inside the node that makes up the list. So I'm not sure if that statement list[x] = 38 is having a problem because of my overloaded operator[] or if it has something to do with the operator=. Any ideas?
Question
Jimmerz28
For this assignment I am to overload the operator[] for a mini List class (basically a watered down list class). I can get the random access to the list by doing list[x] and getting the contents of node x. However when doing reassignments such as:
(the list is a list of integers)
I get this error on UNIX:
I'm guessing that means there is no left hand value in the assignment. Here's my overloaded protocol & body.
(its a templated function)
Protocol:
Body:
template <typename T> T miniList<T>::operator[] (int m) { ? ? ? ?// Allows random type access to the list much like an array ? ? ? ?dnode<T> *curr = (*this).header; ? ? ? ?T temp; ? ? ? ?for (int i = 0; i <= m; i++) ? ? ? ? curr = curr->next; ? ? ? ?temp = curr->nodeValue; ? ? ? ?return temp; }So I'm returning the type of data thats held inside the node that makes up the list. So I'm not sure if that statement list[x] = 38 is having a problem because of my overloaded operator[] or if it has something to do with the operator=. Any ideas?
Link to comment
Share on other sites
4 answers to this question
Recommended Posts