Restriction on interface function types

Steven Schveighoffer schveiguy at yahoo.com
Wed Mar 12 04:56:44 PDT 2014


On Wed, 12 Mar 2014 06:57:08 -0400, Steve Teale  
<steve.teale at britseyeview.com> wrote:

> interface I
> {
>     auto myType();
> }
>
> class A: I
> {
>     auto myType() { return cast(A) null; }
> }
>
> void main()
> {
>     I x = getSomeI();
>     typeof(x.myType()) y;
> }

What you want simply isn't possible. An interface binds at runtime, and  
you need to declare types at compile-time. You can't use an interface  
method to define the type of y.

-Steve


More information about the Digitalmars-d mailing list