Overloading operator, why does it keep prompting error “operator> has invalid parameters count”?

 

Where is the error in this code? Thank you!


struct bar_all
{
   datetime           time;
   double             value;
};
class test   
{
public:
                     test()
   {
   }
                    ~test()
   {}
   bool              operator>(const bar_all &a,const bar_all &b);
};

bool test::operator> (const bar_all &a,const bar_all &b) 
{
 return a.value > b.value;
}
 
  1. Operator> compares the current object to something else. Therefor one parameter.

       bool operator>(const bar_all &that) const{ return this.value > that.value; }
  2. Alternatively, define a stand-alone function (not a class method) that takes two arguments.

  3. Generally you only need to define operator< and operator== and then

    //      doesn't compile with 1154 Jun/15
    //              '>' - semicolon expected
    //              'const' - name expected
    //              '}' - expressions are not allowed on a global scope
    //      #1255686 | 2015.07.08 21:05
    //              Operator Overloading can't be standalone functions 
    //       Service Desk: We do not support overriding global operators yet 
    template <typename T>
    bool     operator>(const T& lhs, const T& rhs){    return   rhs < lhs;         }
    template <typename T>
    bool     operator<=(const T& lhs, const T& rhs){   return !(rhs < lhs);        }
    template <typename T>
    bool     operator>=(const T& lhs, const T& rhs){   return !(lhs < rhs);        }
    template <typename T>
    bool     operator!=(const T& lhs, const T& rhs){   return !(lhs == rhs);       }

 
William Roeder # :
  1. Operator> compares the current object to something else. Therefor one parameter.

  2. Alternatively, define a stand-alone function (not a class method) that takes two arguments.

  3. Generally you only need to define operator< and operator== and then


Excellent! Thank you!