add copy example
This commit is contained in:
parent
a915413008
commit
e166405e4a
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ datatypes/datatypes
|
||||
appending/appending
|
||||
import/import
|
||||
compclass/compclass
|
||||
copy/copy
|
||||
|
12
copy/Makefile
Normal file
12
copy/Makefile
Normal 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
33
copy/copy.d
Normal 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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user