add copyconstructor
This commit is contained in:
1 parent
865caaf37d
commit
3d0f41097f
3 files changed
+39
No files matched your search
@@ -7,3 +7,4 @@ compclass/compclass
|
||||
copy/copy
|
||||
structcons/structcons
|
||||
enum/enum
|
||||
copyconstructor/copyconstructor
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
TARGET := copyconstructor
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(TARGET).d
|
||||
|
||||
%: %.d
|
||||
gdc -o $@ $<
|
||||
|
||||
clean:
|
||||
-rm -f *.o *~ $(TARGET)
|
||||
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user