tags:

views:

88

answers:

1

I have overloaded the [] operator in my class. here is the implementation

Node* List::operator [](int index) const{
    Node* p = head_;

    for (int i = 0; i < index; i++){
            p = p->link();
    }

    return p;
}

I have another function in the class in which I want to access the Node* returned. one of the lines is

if ((n = index_of_name(artistName)) >= 0){
  Node* p = // code needed here
}

I want to be able to access the node at n by using the overloaded[]. How can I do that?

+7  A: 
(*this)[n]
Todd Gardner
or this->operator[](n)
lothar
@lothar - Thanks! I couldn't remember how to use the arrow op to do it, since I always use the above.
Todd Gardner