const(FAQ)
Kevin Bealer
kevinbealer at gmail.com
Sat Mar 29 11:03:35 PDT 2008
Koroskin Denis Wrote:
> 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;
> }
Maybe I'm missing something but checking your code in the version of dmd that I currently have (2.007), the compiler says:
Error: cast(int)(this._area) is not an lvalue
Kevin
More information about the Digitalmars-d
mailing list