Properties don't work as expected

zabruk70 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 5 09:11:58 PDT 2016


On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:
> Property functions are used wrong by a compiler when it needs

i am sorry for my dumbness, what wrong with this code?

import std.stdio;

struct A {
     @property ref int value() {
         return value_;
     }

     @property void value(int v) {
	value_ = v;
     }

private:
	int value_;
}

int main(string[] args) {
	A a;
	a.value = 10;
	writeln(a.value);
	a.value += 20;
	writeln(a.value);
	return 0;
}



More information about the Digitalmars-d-learn mailing list