Status of $ in class/struct?

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Mar 29 19:57:00 PDT 2011


I think its broken or something. It looks like its trying to find
__dollar in the current scope. Because this non-solution seems to
work:

module opDollarTest;

import std.stdio;

class Foo
{
    int[] data;

    this(int[] data)
    {
        this.data = data;
    }

    int opIndex(int a)
    {
        return data[a];
    }

    @property
    size_t length()
    {
        return data.length;
    }

    @property
    size_t opDollar()
    {
        return length;
    }
}

void main()
{
    auto foo = new Foo([1,2,3,4,5]);

    size_t __dollar()
    {
        return foo.opDollar();
    }

    writeln(foo[$-1]);
}


More information about the Digitalmars-d-learn mailing list