TheInsider
Programmer
Hi,
I'm new to C++ and I'm trying to overload the [] operator in a linked list template class; however, I'm getting "impossible conversion type errors". The class looks like:
Then I instantiate the list, in an "Animation" class, using another class I created called "Image". Basically, the logic is that Animation has a linked list of Image(s).
...and then, after adding some items to the list, attempt to access the list from within the "Animation" class via the overloaded [] operator:
And the errors that I am receiving are:
Obviously, the errors are referring to the return value of the T* operator [](unsigned long index) method.
Any help is greatly appreciated.
Thanks
I'm new to C++ and I'm trying to overload the [] operator in a linked list template class; however, I'm getting "impossible conversion type errors". The class looks like:
Code:
template <typename T> class LinkedList
{
private:
template <typename T> struct Node
{
T *object;
Node<T> *next,
*previous;
};
Node<T> *head,
*tail;
unsigned long size;
public:
...
T* operator [](unsigned long index)
{
Node<T> *current = head;
if (index != 0)
{
while ((current != NULL) && (index-- > 0))
{
current = current->next;
}
}
return (current != NULL) ? current->object : NULL;
}
};
Code:
LinkedList<Image> *list;
Code:
Image* get_current_frame(void)
{
//current_index is an unsigned long private member variable
return list[current_index];
}
space.cpp(279): Error! E324: col(28) conversion of return value is impossible
space.cpp(279): Note! N630: col(28) source conversion type is 'LinkedList<Image> (lvalue)'
space.cpp(279): Note! N631: col(28) target conversion type is 'Image *'
Obviously, the errors are referring to the return value of the T* operator [](unsigned long index) method.
Any help is greatly appreciated.
Thanks