Thread overview | |||||
---|---|---|---|---|---|
|
February 10, 2005 [documentation] bad C++ code | ||||
---|---|---|---|---|
| ||||
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 Re: [documentation] bad C++ code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | 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 Re: [documentation] bad C++ code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Good catch. Fixed. -Walter |
Copyright © 1999-2021 by the D Language Foundation