www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [documentation] bad C++ code

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
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; }
Feb 09 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Andrew Fedoniouk wrote:
 source: http://www.digitalmars.com/d/cpptod.html#operatoroverloading

 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.
Feb 10 2005
parent "Walter" <newshound digitalmars.com> writes:
Good catch. Fixed. -Walter
Feb 10 2005