Error: cannot implicitly convert expression
Agustin
wolftein1 at gmail.com
Tue Jun 18 15:34:34 PDT 2013
On Tuesday, 18 June 2013 at 21:43:17 UTC, Agustin wrote:
> On Tuesday, 18 June 2013 at 21:39:35 UTC, Agustin wrote:
>> Hello!, i'm having a problem and i don't know how to fix it :(.
>>
>> /**
>> * Define a common structure for any event.
>> *
>> * @author Wolftein <wolftein at ghrum.org>
>> */
>> public class Event(T) {
>>
>> private bool cancelled_;
>> private shared static HandlerList!T handler_;
>>
>> /**
>> * Return if the event was cancelled.
>> */
>> final public bool isCancelled() {
>> return cancelled_;
>> }
>>
>> /**
>> * Set the cancelled flag.
>> *
>> * @param cancelled the cancelled flag value
>> */
>> final public void setCancelled(bool cancelled) {
>> cancelled_ = cancelled;
>> }
>>
>> /**
>> * Gets the unique handler of the event, the handler
>> * contains a list of delegates to be executed when
>> * the event triggers an action.
>> */
>> final public HandlerList!T getHandler() {
>> return handler_;
>> }
>>
>> /**
>> * Gets the unique handler of the event, the handler
>> * contains a list of delegates to be executed when
>> * the event triggers an action. This function is
>> * static, so can be called like Template.getHandler()
>> */
>> final public HandlerList!T getHandler() {
>> return handler_;
>> }
>> }
>>
>> ---------------------------------------------------------------
>> class PlayerLoginEvent : Event!(PlayerLoginEvent) {
>> int x;
>> }
>>
>> src\Event\Event.d(41): Error: cannot implicitly convert
>> expression (handler_) of type shared(HandlerList) to
>> ghrum.event.HandlerList.HandlerList!(PlayerLoginEvent).HandlerList
>> src\Event\Event.d(51): Error: cannot implicitly convert
>> expression (handler_) of type shared(HandlerList) to
>> ghrum.event.HandlerList.HandlerList!(PlayerLoginEvent).HandlerList
>
>
> The last function is:
>
> final static public HandlerList!T getHandler() {
> return handler_;
> }
I just fixed by replacing shared with __gshared. Another issue
that i have is that if i have.
public class Event(T) {
static public HandlerList!T getHandler() {
if( handler_ is null ) {
handler_ = new HandlerList!T();
}
return handler_;
}
}
public class MyPlayerEvent : Event!MyPlayerEvent {
}
MyPlayerEvent.getHandler(); -> Error: need 'this' for getHandler
type HandlerList().
Thanks in advance!
More information about the Digitalmars-d-learn
mailing list