Hey guys, im having some trouble in finding what I should return with the [] operator overloading. Here is my implementation code:
template <typename L>
L& List<L>::operator[](int index) throw (ListException)
{
if (index >= length || index < 0)
{
throw ("In function: operator[]: index >= length or < 0");
}
else
{
Node<L>* ptr = first;
ptr->next = first->next;
int cnt=0;
while (cnt < index)
{
ptr = ptr->next;
cnt++;
}
}
return *ptr->data;
}
I keep getting the error: 'ptr' was not declared in this scope
It gives me this error at the line
return *ptr->data;
I cant figure out what return value I need to use. I know it shouold be L&, which is a dereferenced value of one module of that list...but im having trouble. Ive tried simply ptr->data, among many other things. Any help would be greatly appreciated! Thanks! =)