const on a function forbids changing members:

class Wrong {
    int a;
    void foo() const {
        a = 4;
    }
}

The above rightly doesn't compile. But with a little twist...

class A {
    int a;
    void foo(ref int i) const {
        i = 4;
    }
    void foo() const {
        foo(a);
    }
}

void main() {
    auto a = new A;
    a.foo;
    assert(a.a == 4);
}

... I bypass the const promise on a function (two of them in fact). No casting, 
no evil stuff.

Is this a compiler bug or feature?

Tomek

Reply via email to