From a9154130082fc06136770840d77702be97ae516d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 15 Feb 2013 19:28:28 -0500 Subject: [PATCH] add compclass --- .gitignore | 1 + compclass/Makefile | 12 ++++++++++++ compclass/compclass.d | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 compclass/Makefile create mode 100644 compclass/compclass.d diff --git a/.gitignore b/.gitignore index 6c33f84..4ccd6c9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ factorial/factorial datatypes/datatypes appending/appending import/import +compclass/compclass diff --git a/compclass/Makefile b/compclass/Makefile new file mode 100644 index 0000000..bd09dbd --- /dev/null +++ b/compclass/Makefile @@ -0,0 +1,12 @@ + +TARGET := compclass + +all: $(TARGET) + +$(TARGET): $(TARGET).d + +%: %.d + gdc -o $@ $< + +clean: + -rm -f *.o *~ $(TARGET) diff --git a/compclass/compclass.d b/compclass/compclass.d new file mode 100644 index 0000000..26a4ba4 --- /dev/null +++ b/compclass/compclass.d @@ -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); +}