What functions can be called on a shared struct that's implicitly castable to immutable?

deadalnix deadalnix at gmail.com
Sun Nov 3 21:53:50 PST 2013


On Sunday, 3 November 2013 at 21:55:22 UTC, Simen Kjærås wrote:
> Consider:
>
> module foo;
>
> struct S {
>     immutable(int)[] arr;
>     void fuzz() const pure {
>     }
> }
>
> void bar(S s) {
>     s.fuzz();
> }
>
> void main() {
>     shared S s;
>     bar(s);   // a
>     s.fuzz(); // b
> }
>
>
> In this case, the line marked 'a' works perfectly - it compiles 
> and does what I'd expect it to.
>
> However,the line marked 'b' does not compile - " non-shared 
> const method foo.S.fuzz is not callable using a shared mutable 
> object ".
>

It is because a imply a pass b value, when b a pass by reference.


More information about the Digitalmars-d mailing list