As far as i know "int" is not immutable or const by default.
So, why work this code:

[code]
import std.stdio;

class Bar {
        
}

class Foo {
private:
        int _id;
        
        Bar _b;
        
public:
        this(int id, Bar b) {
                this._id = id;
                
                this._b = b;
        }
        
// const_behaviour.d(18): Error: cannot implicitly convert expression (this._b) of type const(Bar) to const_behaviour.Bar const(Bar) GetB() const pure nothrow { /// <- must be const(Bar) instead of Bar
                return this._b;
        }
        
int GetId() const pure nothrow { /// <- no const(int) is neccessary. Why?!
                return this._id;
        }
}

void main() {
        Bar b = new Bar();
        
        Foo f = new Foo(42, b);
}
[/code]

Reply via email to