add copyconstructor
This commit is contained in:
parent
865caaf37d
commit
3d0f41097f
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ compclass/compclass
|
|||||||
copy/copy
|
copy/copy
|
||||||
structcons/structcons
|
structcons/structcons
|
||||||
enum/enum
|
enum/enum
|
||||||
|
copyconstructor/copyconstructor
|
||||||
|
12
copyconstructor/Makefile
Normal file
12
copyconstructor/Makefile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
TARGET := copyconstructor
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(TARGET).d
|
||||||
|
|
||||||
|
%: %.d
|
||||||
|
gdc -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f *.o *~ $(TARGET)
|
26
copyconstructor/copyconstructor.d
Normal file
26
copyconstructor/copyconstructor.d
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
static int count;
|
||||||
|
int f1;
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
f1 = 42;
|
||||||
|
writefln("Constructed a Foo, %d exist!", count);
|
||||||
|
}
|
||||||
|
this(Foo f)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
writefln("Copied a Foo, %d exist! f1: %d", count, f1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Foo foo1 = new Foo();
|
||||||
|
Foo foo2 = new Foo();
|
||||||
|
Foo foo3 = new Foo(foo1);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user