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 05:35:17 PDT 2014
In a class I defined an event attribute as follows:
public void delegate( shared(SocketListener) sender )
eventWhenStarted;
---
An instance of SocketListener is created.
auto listener = new shared SocketListener();
---
I defined a shared method that will be called when the event
occurs.
public void listener_whenStarted( shared(SocketListener) sender )
shared{}
---
I set the event attribute of listener to defined method:
listener.eventWhenStarted = &listener_whenStarted;
----
Here is the error message:
main.d(21): Error: cannot implicitly convert expression
(&this.listener_whenStarted) of type void
delegate(shared(SocketListener) sender) shared to shared(void
delegate(shared(SocketListener)))
If we look at types separately as follows:
.......void delegate(shared(SocketListener) sender) shared
shared(void delegate(shared(SocketListener)))
Isn't the first type same as the second one?
(1.5 years later, I still hate the `shared` keyword. It is
nothing but confusion and extra coding for many programmers.)
More information about the Digitalmars-d-learn
mailing list