add compclass
This commit is contained in:
parent
80973ceb8c
commit
a915413008
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ factorial/factorial
|
||||
datatypes/datatypes
|
||||
appending/appending
|
||||
import/import
|
||||
compclass/compclass
|
||||
|
12
compclass/Makefile
Normal file
12
compclass/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
TARGET := compclass
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(TARGET).d
|
||||
|
||||
%: %.d
|
||||
gdc -o $@ $<
|
||||
|
||||
clean:
|
||||
-rm -f *.o *~ $(TARGET)
|
29
compclass/compclass.d
Normal file
29
compclass/compclass.d
Normal file
@ -0,0 +1,29 @@
|
||||
import std.stdio;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
int a;
|
||||
int b;
|
||||
override bool opEquals(Object o_other)
|
||||
{
|
||||
Foo other = cast(Foo) o_other;
|
||||
return a == other.a && b == other.b;
|
||||
}
|
||||
};
|
||||
|
||||
void main(string[] args)
|
||||
{
|
||||
Foo f = new Foo();
|
||||
f.a = 1;
|
||||
f.b = 2;
|
||||
Foo g = new Foo();
|
||||
g.a = 1;
|
||||
g.b = 2;
|
||||
Foo h = new Foo();
|
||||
h.a = 1;
|
||||
h.b = 3;
|
||||
writefln("f == g: %s", f == g);
|
||||
writefln("f == h: %s", f == h);
|
||||
writefln("g == h: %s", g == h);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user