From f557efcb868fc0513b021ca6f15b03a1f4808db7 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 12 Jul 2018 15:25:10 -0400 Subject: [PATCH] add property example --- .gitignore | 1 + property/Makefile | 11 +++++++++++ property/property.d | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 property/Makefile create mode 100644 property/property.d diff --git a/.gitignore b/.gitignore index b0ddf06..68e7301 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ copy/copy structcons/structcons enum/enum copyconstructor/copyconstructor +property/property diff --git a/property/Makefile b/property/Makefile new file mode 100644 index 0000000..eb32136 --- /dev/null +++ b/property/Makefile @@ -0,0 +1,11 @@ +TARGET := property + +all: $(TARGET) + +$(TARGET): $(TARGET).d + +%: %.d + gdc -o $@ -Wall $< + +clean: + -rm -f *.o *~ $(TARGET) diff --git a/property/property.d b/property/property.d new file mode 100644 index 0000000..0b4274c --- /dev/null +++ b/property/property.d @@ -0,0 +1,22 @@ +import std.stdio; + +class A +{ + int a() { return 10; } + void a(int x) + { + writefln("Setting a to %d", x); + } + void a(int x, int y) + { + writefln("a(%d, %d)", x, y); + } +}; + +void main() +{ + auto a = new A; + writeln(a.a); + a.a = 42; + a.a(42, 33); +}