On Friday, 20 May 2016 at 18:23:26 UTC, Jack Applegame wrote:
On Friday, 20 May 2016 at 17:28:55 UTC, Namespace wrote:
But you can cheat:
You can just cast const away:
struct A {
        int id = 0;
        
        this(int id) {
                this.id = id;
        }
        
        void change() const {
                (cast() id)++;
        }
}

void main() {
        import std.stdio;
        
        A a = A(42);
        a.change();
        
        writeln(a.id);
}


Is it valid code (I'm asking about undefined behavior)?

Reply via email to