shared class constructor

Robert Jacques sandford at jhu.edu
Thu Aug 13 10:42:21 PDT 2009


On Thu, 13 Aug 2009 09:34:50 -0700, Jeremie Pelletier <jeremiep at gmail.com>  
wrote:

> Just came across this while porting my code to enforce the use of shared.
>
> ---
> module test;
> shared class Foo {
>    this() {}
> }
> ---
> Error: cannot implicitly convert expression (this) of type shared(Foo)  
> to test.Foo
>
> Of course I could just use new shared(Foo) but that would allow  
> non-shared instances of Foo to be created as well, which I do not want.
>
> Shouldn't "this" resolve to the fully qualified class?

In general, shared classes right now are broken. For example, you can't  
actually write any shared methods yet, (bug 3089) amoung other things.  
This does look like something new, and should be added.

As for your question: given that immutable classes work the same way, I  
assume it should.



More information about the Digitalmars-d mailing list