Original Post
For the purpose of learning I''ve been working on a linked_list class. The linked list contains various methods, and a pointer to the head and a pointer to the tail which point to node objects. Each node has a pointer to data. Both linked_list and node are templated to hold any kind of data.
Yes, I know the std exists. No, I don''t want to use it instead. I like learning how things work and creating something on my own. I will probably use it later, but for now, I would like to knwo how something like this works.
Anyways. I''ve overloaded the subscript operator. I was hoping to get a more intuitive use out of the linked list. But using [] actually makes things more confusing. Its obvious I''m not implementing it correctly.
template <typename T>
T& LINKED_LIST<T>::operator[] (int subscript){
if(subscript>members)
return NULL;
long start = 0;
NODE<T>* cur_node=head;
while(start!=subscript){
cur_node=cur_node->next;
start++;
}
return cur_node->data;
}
I would like to return the data of the node, rather than the node itself as to create a layer of transparency.
To use it, I have to use
i=(&(*uvpoly_list)[n])->somememberofdata;
Alas. VERY counter-intuitive.
I''ve tried googleing "operator[]" However, all symbols are left out of searches so im limited to searching ''subscript operator''
I would search for operator-> but I have no idea what its name even is. :-/
Sorry for the long post. I tend to explain too much.
Maybe someone can point me in the right direction. Thanks in advance.