The main advantage of defining operators as non-member global functions
is that the compiler performs implicit conversions on the first argument.
For example:
class Date{
public:
Date(int d=30, m=1, y=1997) day(d), mon(m), year(y) {}
Date operator+(Date& );
friend Date operator+(Date& , Date& );
// Other public members go here
private:
day, mon, year;
};
int main(){
Date d1, d2;
d1 = 30 + d2; // Will work for global version only
d1 = Date(30) + d2; // Will work for either version
d1 = d2 + 30; // Will work for either version
return 0;
}