No Match for Operator >

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.
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.
In your person class you need to implement this function:

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