Weird template error
Jarrett Billingsley
jarrett.billingsley at gmail.com
Wed Nov 19 15:39:49 PST 2008
On Wed, Nov 19, 2008 at 4:59 PM, Brian <digitalmars at brianguertin.com> wrote:
> I don't understand why we wouldn't want properties either. Another issue
> I've had a couple times, although there might be a good reason for this
> I'm not aware of:
>
> class Foo {
> int x;
> }
>
> void set(inout int x) {
> x = 10;
> }
>
> void main() {
> auto foo = new Foo();
> set(foo.x); // This works fine
> }
>
> But then if you need to make x a property:
>
> class Foo {
> int _x;
>
> int x() { return _x; }
> int x(int val) { return _x = val; }
> }
>
> You get "Error: foo.x() is not an lvalue"
That one's trickier, even if you did have properties. Even "true"
properties would still boil down to a function call. Set expects a
reference to an integer. How do you convert getter/setter functions
into an integer?
It doesn't work now because foo.x is a function, not an int.
Also, I wonder if ref returns could help here..
More information about the Digitalmars-d
mailing list