Cannot implicitly convert derived type

Eric Suen eric.suen.tech at gmail.com
Sat Feb 22 20:35:49 PST 2014


interface iButton { }

class WindowsButton : iButton { }

interface iGui(T)
{
@property T button(ref T button);
}

class WindowsGui : iGui!(WindowsButton)
{
 @property WindowsButton button(ref WindowsButton button) {
  return button;
 }
}

"Frustrated" <c1514843 at drdrb.com>
> On Saturday, 22 February 2014 at 05:20:25 UTC, Eric Suen wrote:
>> Generic?
>>
>
> I don't see how this would help. I'd have to specify every
> concrete type in the creation of the object which might be
> significant. I can't use a generic virtual method so that doesn't
> help either.
>
> It would be nice to have something like
>
> T foo(T : iButton)(T button);
>
> Which then I override with
>
> WindowsButton foo(WindowsButton button) { }
>
> Since WindowsButton is derived from iButton. The compiler would
> have to insert a type check to make sure when I called the first
> one(from the interface) that it was a windows button that was
> passed(since any iButton could be passed) when using the
> WindowsGui.
>
> The main point of all this is simply efficiency. I have to liter
> the code with checks and casts when it is entirely possible to
> get the compiler to automate it all. By doing so one can program
> the concrete class in a much more natural way.
>
> 




More information about the Digitalmars-d-learn mailing list