Dynamic Arrays & Class Properties

Sergey Gromov snake.scaly at gmail.com
Thu Aug 28 11:22:44 PDT 2008


Mason Green <mason.green at gmail.com> wrote:
> Hi,
> 
> Anyone know how to expose dynamic array elements via class properties?  I would like to do something this this:
> 
> class Foo {
> 
>     private int[] m_dummy;
> 
>     this() {
>         m_dummy ~= 19;
>         m_dummy ~= 77;
>     }
> 
>     int dummy( ??????? ) {
>         return m_dummy[x];
>     }
> }
> 
> void main() {
>     auto foo = new Foo();
>     Cout(foo.dummty[0]);     // Print 19
> }
> 
> Any help would be much appreciated!  The question marks are where I'm stuck....

class Foo {
    private int[] m_dummy;
    const int dummy() {
        return m_dummy;
    }
}

I think this is better than tons of templates.

-- 
SnakE


More information about the Digitalmars-d-learn mailing list