public interface IAutomatizableEvent
{
Event AutomatizableEventItem { get; }
bool CanBeAutomatic { get; }
bool IsAutomaticallyRunning { get; }
bool OnBeforeAutomaticCall();
bool OnAutomaticCheck();
void OnAutomaticStart();
void OnAutomaticCancel();
}
public abstract class AutomatizableEvent : IAutomatizableEvent
{
public AutomatizableEvent()
{
}
#region Implementation of IAutomatizableEvent
public abstract Event AutomatizableEventItem { get; }
public abstract bool CanBeAutomatic { get; }
public abstract bool IsAutomaticallyRunning { get; }
public abstract bool OnBeforeAutomaticCall();
public abstract bool OnAutomaticCheck();
public abstract void OnAutomaticStart();
public abstract void OnAutomaticCancel();
#endregion
}
public static class EventSystem
{
public static List<EventSystemBase<Event, AutomatizableEvent>> AutomatizableEvents { get; set; }
[...]
}
"The type 'AutomatizableEvent' must have a public parameterless constructor in order to use it as parameter 'K' in the generic class 'EventSystemBase'"
public abstract class EventSystemBase<T, K> : AutomatizableEvent
where T : Event
where K : AutomatizableEvent, new()
My question is ... doesn't AutomatizableEvent DO HAVE a public parameterless constructor??
The error description is wrong, but the error is correct.
AutomatizableEvent
cannot be used as generic parameter K
because of the constraint where K : new()
. An abstract class does not satisfy that constraint.
A constructor of an abstract class is effectively protected, always, since an abstract can only ever be created as a base subobject of a derived class, the constructor can likewise only ever be called by a constructor of a derived class, and only in constructor chaining. Specifically it can't be used by EventSystemBase<T, K>
in the context new K()
.
you can't instantiate an abstract class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With