-1

I'm trying to overload the comparision operator.

How can i overload the comparison operator == for this function? c++

template <class elemType>
    void ArrayList<elemType>::RetrieveItem(elemType & item, bool& found) {
        for (int i = 0; i < n_element; i++)
        {
            if (data[i].getName() == item.getName())
            {
                found = true;
                item = data[n_element];
            }
        }
Shubham R
  • 7,382
  • 18
  • 53
  • 119
  • Pay attention to this code - i think you can go out of bounds if array consist of n_element item = data[n_element]; <----------------- – Boris Bolshem Apr 09 '17 at 08:31

1 Answers1

-1

from the looks of it, you are comparing 2 strings. overloading comparison operator would go into the class definition for whatever getName() returns

You can see lots of information regarding operator overloading in this post

Community
  • 1
  • 1