Placement of shared does not allow to set a delegate

Tolga Cakiroglu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 16 09:25:03 PDT 2014


Thanks Ali. That has solved the problem. Actually I tried to use 
that `shared` as follows before:

public shared void delegate( shared(BasicSocketListener) sender ) 
eventWhenStarted;

Though it didn't work with that. When it is put "before" the 
attribute name, it works now. It is just confusing where to put 
it to.

On Monday, 16 June 2014 at 15:25:51 UTC, Ali Çehreli wrote:
>
> Here is a minimal example that reproduces the issue and the 
> hint that compiles the code:
>
> class SocketListener
> {
>     public void delegate( shared(SocketListener) sender )
>     /* shared */    // <-- UNCOMMENT TO COMPILE
>     eventWhenStarted;
> }
>
> class C
> {
>     this()
>     {
>         auto listener = new shared SocketListener();
>         listener.eventWhenStarted = &listener_whenStarted;
>     }
>
>     public void listener_whenStarted( shared(SocketListener) 
> sender ) shared
>     {}
> }
>
> void main()
> {}
>
> Error: cannot implicitly convert expression 
> (&this.listener_whenStarted) of type void 
> delegate(shared(SocketListener) sender) shared to shared(void 
> delegate(shared(SocketListener)))
>
> Ali



More information about the Digitalmars-d-learn mailing list