This is a function within my doubly linked list class, but every time I compile, I get this message: "Invalid initialization of non-const reference of type 'int&' from a temporary of type 'int'. I just can't get how else to do it.
int& LinkedList::operator[](int index)
{
Node* current = head_;
for(int i = 0; i < index; i++){
current = current->getNextNode();
}
return(current->getValue()); // getValue() returns an int
}
Thanks in advance!
list[i] = 42wouldn't work as expected.