add property example

This commit is contained in:
Josh Holtrop 2018-07-12 15:25:10 -04:00
parent 3d0f41097f
commit f557efcb86
3 changed files with 34 additions and 0 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ copy/copy
structcons/structcons
enum/enum
copyconstructor/copyconstructor
property/property

11
property/Makefile Normal file
View File

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

22
property/property.d Normal file
View File

@ -0,0 +1,22 @@
import std.stdio;
class A
{
int a() { return 10; }
void a(int x)
{
writefln("Setting a to %d", x);
}
void a(int x, int y)
{
writefln("a(%d, %d)", x, y);
}
};
void main()
{
auto a = new A;
writeln(a.a);
a.a = 42;
a.a(42, 33);
}