add compclass

This commit is contained in:
Josh Holtrop 2013-02-15 19:28:28 -05:00
parent 80973ceb8c
commit a915413008
3 changed files with 42 additions and 0 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ factorial/factorial
datatypes/datatypes
appending/appending
import/import
compclass/compclass

12
compclass/Makefile Normal file
View 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
View 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);
}