From e166405e4a42819b86de028dae807665303616de Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 15 Feb 2013 20:05:45 -0500 Subject: [PATCH] add copy example --- .gitignore | 1 + copy/Makefile | 12 ++++++++++++ copy/copy.d | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 copy/Makefile create mode 100644 copy/copy.d diff --git a/.gitignore b/.gitignore index 4ccd6c9..4cd59a0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ datatypes/datatypes appending/appending import/import compclass/compclass +copy/copy diff --git a/copy/Makefile b/copy/Makefile new file mode 100644 index 0000000..8f337bd --- /dev/null +++ b/copy/Makefile @@ -0,0 +1,12 @@ + +TARGET := copy + +all: $(TARGET) + +$(TARGET): $(TARGET).d + +%: %.d + gdc -o $@ $< + +clean: + -rm -f *.o *~ $(TARGET) diff --git a/copy/copy.d b/copy/copy.d new file mode 100644 index 0000000..69f4af5 --- /dev/null +++ b/copy/copy.d @@ -0,0 +1,33 @@ + +import std.stdio; + +struct S +{ + int a; + int b; +}; + +class C +{ + int a; + int b; +}; + +void main(string[] args) +{ + S s1; + s1.a = 3; + s1.b = 4; + S s2 = s1; + s2.a = 5; + s2.b = 6; + writefln("S: %d, %d; %d, %d", s1.a, s1.b, s2.a, s2.b); + + C c1 = new C(); + c1.a = 10; + c1.b = 11; + C c2 = c1; + c2.a = 12; + c2.b = 13; + writefln("C: %d, %d; %d, %d", c1.a, c1.b, c2.a, c2.b); +}