On Thursday, 15 March 2018 at 11:18:48 UTC, Robert-D wrote:
struct S {
string[string] aa;

    S dup() inout pure {
        return S(aa);
    }
}

void main() {
        auto s = S(["": ""]);
    s.dup();
}

Result:
Error: cannot implicitly convert expression this.aa of type inout(string[string]) to string[string]


I need help with the above program.


This is where things go wrong:
    S dup() inout pure {

'inout' means that this function can keep the const, immutable or mutable status of the type on which the function is called. This means that an inout function has to treat the object as const, because otherwise the function would break the guarantees of immutable and const.

When using inout on a function, you always want to put inout on something else too - either a ref parameter or the return value. In your case, this works:

    inout(S) dup() inout pure {
        return inout(S)(aa);
    }

--
  Simen

Reply via email to