diff --git a/.gitignore b/.gitignore index 0f300de..b0ddf06 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ compclass/compclass copy/copy structcons/structcons enum/enum +copyconstructor/copyconstructor diff --git a/copyconstructor/Makefile b/copyconstructor/Makefile new file mode 100644 index 0000000..eb28ae5 --- /dev/null +++ b/copyconstructor/Makefile @@ -0,0 +1,12 @@ + +TARGET := copyconstructor + +all: $(TARGET) + +$(TARGET): $(TARGET).d + +%: %.d + gdc -o $@ $< + +clean: + -rm -f *.o *~ $(TARGET) diff --git a/copyconstructor/copyconstructor.d b/copyconstructor/copyconstructor.d new file mode 100644 index 0000000..8279901 --- /dev/null +++ b/copyconstructor/copyconstructor.d @@ -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); +}