Thread overview
[documentation] bad C++ code
Feb 10, 2005
Andrew Fedoniouk
Feb 10, 2005
Stewart Gordon
Feb 10, 2005
Walter
February 10, 2005
source: http://www.digitalmars.com/d/cpptod.html#operatoroverloading

instead of:

struct A
	{
		virtual int operator <  (int i);
		virtual int operator <= (int i);
		virtual int operator >  (int i);
		virtual int operator >= (int i);

		static int operator <  (int i, A *a) { return a >  i; }
		static int operator <= (int i, A *a) { return a >= i; }
		static int operator >  (int i, A *a) { return a <  i; }
		static int operator >= (int i, A *a) { return a <= i; }
	};

shall be written this:

 struct A
 {
  int operator <  (int i);
  int operator <= (int i);
  int operator >  (int i);
  int operator >= (int i);
 };

 int operator <  (int i, A &a) { return a >  i; }
 int operator <= (int i, A &a) { return a >= i; }
 int operator >  (int i, A &a) { return a <  i; }
 int operator >= (int i, A &a) { return a <= i; }




February 10, 2005
Andrew Fedoniouk wrote:
> source: http://www.digitalmars.com/d/cpptod.html#operatoroverloading
<snip>
> shall be written this:
> 
>  struct A
>  {
>   int operator <  (int i);
>   int operator <= (int i);
>   int operator >  (int i);
>   int operator >= (int i);
>  };
> 
>  int operator <  (int i, A &a) { return a >  i; }
>  int operator <= (int i, A &a) { return a >= i; }
>  int operator >  (int i, A &a) { return a <  i; }
>  int operator >= (int i, A &a) { return a <= i; }

And even the D way is wrong.  Should be:

    struct A
    {
        int opCmp(int i);
    }

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
February 10, 2005
Good catch. Fixed. -Walter