digitalmars.D.learn - Is this really a bug?
- Daniel (9/9) Jan 06 2012 Hi, I've read on Bugzilla Issue 6398 that this is a bug:
- Peter Alexander (5/14) Jan 06 2012 It is convenient syntax, but sometimes you want the getter to return a
- Daniel (1/1) Jan 07 2012 Oh, right, thanks!
Hi, I've read on Bugzilla Issue 6398 that this is a bug: static int value; ref foo(){ printf("getter\n"); return value; } ref foo(int x){ printf("setter\n"); value = x; return value; } void main(){ foo = 1; } // Should print "setter", but print "getter" in 2.054 But, this is pretty convenient syntax, no? That way you could implement only one function foo() and use it as setter and getter. I'm a bit confused about it. Thanks, Daniel
Jan 06 2012
On 7/01/12 1:19 AM, Daniel wrote:Hi, I've read on Bugzilla Issue 6398 that this is a bug: static int value; ref foo(){ printf("getter\n"); return value; } ref foo(int x){ printf("setter\n"); value = x; return value; } void main(){ foo = 1; } // Should print "setter", but print "getter" in 2.054 But, this is pretty convenient syntax, no? That way you could implement only one function foo() and use it as setter and getter. I'm a bit confused about it. Thanks, DanielIt is convenient syntax, but sometimes you want the getter to return a ref, but want the setter to do something different to "getter() = x". This bug says that there is no way to override a ref returning getter with a custom setter.
Jan 06 2012