No Match for Operator >

Feb 8, 2013 at 4:33am
The following is an insert sorting algorithm that is part of a larger program.

I have refined this program to the point that I only get this one error.

1
2
3
4
5
6
7
8
9
10
11
12
Person Insert;
   for (int Next = 1; Next < increment; ++Next)
   {
      Insert = People[Next];
      int MoveItem = Next;
      while ((Next > 0) && ((People[Next-1]) > (Insert))) // Error: No match for 'operator>' in "People[Next-1] > Insert", where operator> reffers to the logical operator ">" between Next-1 and Insert.
      {
          People[MoveItem] = People[MoveItem-1]; 
          MoveItem--;
      }
      People[MoveItem] = Insert;     
   }


This problem has got me stumped. I cannot figure out why such an operator would not be valid. Also, as a side note, replacing ">" with "<" makes the error read "No match for 'operator "<"...", so it is not the type of operator that is the problem.

Any help on this is much appreciated, as I have already gone to office hours once, and gotten help from a friend.
Feb 8, 2013 at 5:25am
People[Next-1] returns a person? You will need to overload the > operator in your Person class to compare the values that you need to compare.
Feb 8, 2013 at 7:02am
In your person class you need to implement this function:

1
2
3
4
bool Person::operator > (Person& rhs)
{
    return this->SomeMemberAttribute > rhs.SomeMemberAttribute;
}
Feb 8, 2013 at 2:22pm
That actually produces the same error in what is your line 3. What does such an error literally mean?
Feb 8, 2013 at 2:44pm
It means that the compiler doesn't understand what 'greater than' means when comparing Person objects.
Topic archived. No new replies allowed.