codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
class UncomparableException: Exception { this() { super(""); } this(string msg) { super(msg); } } class C1 { // WRONG? int x; this(int x) { this.x = x; } int opEquals(Object o) { auto oc = cast(typeof(this))o; if (oc is null) return 0; else return this.x == oc.x; } int opCmp(Object o) { // ... } } class C2 { // RIGHT? int x; this(int x) { this.x = x; } int opEquals(Object o) { auto oc = cast(typeof(this))o; if (oc is null) throw new UncomparableException(); else return x == oc.x; } int opCmp(Object o) { auto oc = cast(typeof(this))o; if (oc is null) throw new UncomparableException(); else return this.x - oc.x; } } void main() {}
Private
[
?
]
Run code
Submit