Sharing in D

Walter Bright newshound1 at digitalmars.com
Fri Aug 1 10:08:19 PDT 2008


Sean Kelly wrote:
> What about this:
> 
>     shared ClassA a;
> 
>     void main()
>     {
>         ClassB b = a.getB();
>         b.mutate();
>     }
> 
> I'd imagine the checking will catch common mistakes but not issues
> like the above?  Or will the fact that 'b' is being returned from
> a require the declaration of 'b' to be shared because the value
> may be accessed by both ClassA and anything outside ClassA?

Shared cannot be implicitly cast to unshared. Just like const cannot be 
implicitly cast to mutable.



More information about the Digitalmars-d mailing list