overloading operator <

  1. 2 weeks ago

    Brian O

    Oct 11 Pre-Release Testers, Xojo Pro Calgary, AB

    I am trying to overload operator compare.
    however the right hand side is nil.
    what does one do in operator compare if the right hand side is nil?
    throw an exception?
    throw or raise?
    what?

  2. Dave S

    Oct 11 San Diego, California USA

    a value is never < or > nil
    it is = Nil or <> Nil

    so you would need to make that check BEFORE you attempt < or >

  3. Kem T

    Oct 11 Pre-Release Testers, Xojo Pro New York

    It will send Nil to your Operator_Compare and you should return 1 or -1 depending on how you'd want it sorted, if you care.

    Function Operator_Compare (other As MyClass) As Integer
      if other is nil then
        return 1 // or -1
      end if
    End Function

    BTW, this is why I always use o is nil to bypass any custom Operator_Compare, or I make a clear note as to why I want Operator_Compare to do the work.

or Sign Up to reply!