const(FAQ)

Koroskin Denis 2korden+D at gmail.com
Sat Mar 29 05:08:07 PDT 2008


Slightly modifying your example...

Looks like a bug to me:

import std.stdio;

void set(inout int key, int value)
{
     key = value;
}

class Square {
     private int _area = -1;
     private int _width = 0;

     public this(int width)
     {
         _width = width;
     }

     public const int area()
     {
         if (_area == -1) {
             //_area = _width*_width;      // we cannot change variable  
value direcly
             set(_area, _width*_width);    // but we can do it _indirectly_  
???
                                           // it means that _all_ variables  
are mutable!
         }
         return _area;
     }
}

int main(string[] args)
{
     const Square c = new Square(10);
     writefln(c.area());

     return 0;
}



More information about the Digitalmars-d mailing list