add copy example

This commit is contained in:
Josh Holtrop 2013-02-15 20:05:45 -05:00
parent a915413008
commit e166405e4a
3 changed files with 46 additions and 0 deletions

1
.gitignore vendored
View File

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

12
copy/Makefile Normal file
View File

@ -0,0 +1,12 @@
TARGET := copy
all: $(TARGET)
$(TARGET): $(TARGET).d
%: %.d
gdc -o $@ $<
clean:
-rm -f *.o *~ $(TARGET)

33
copy/copy.d Normal file
View File

@ -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);
}