add copyconstructor

This commit is contained in:
Josh Holtrop 2013-03-10 18:00:54 -04:00
parent 865caaf37d
commit 3d0f41097f
3 changed files with 39 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ compclass/compclass
copy/copy
structcons/structcons
enum/enum
copyconstructor/copyconstructor

12
copyconstructor/Makefile Normal file
View File

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

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