I'm overloading an operator[]:
const Type&& operator[](int index) const {
if (index >= size) { std::cout << "Error: excessive index.\n"; return 0; }
else if (index < 0) { std::cout << "Error: negative index.\n"; return 0; }
else {
Node* temp = head->next;
for (int i = 0; i < index; i++) { temp = temp->next; }
return temp->value;
}
}
But I need a duplicate of it, which will return non-const Type value. I read that we can use perfect forwarding for cases when arguments of function can be both const or non-const (so that we wrap them in forward<Type> every time we use it), but how to use it for value that is returned?
Also, if I simply want to return nothing, should I write return 0; or return NULL;? Which is more understandable?