Final makes no difference?
Sean Kelly
sean at f4.ca
Thu Aug 24 13:58:44 PDT 2006
Chris Nicholson-Sauls wrote:
>
> Tested with DMD 0.165, no errors, runs perfectly:
>
> # module funcface0;
> #
> # import std .stdio ;
> #
> # interface Foo {
> # char[] str () ;
> # int num () ;
> # }
> #
> # void bar (Foo f) {
> # writefln("str('%s') num(%d)", f.str(), f.num());
> # }
> #
> # void func (char[] s, int n) {
> # Foo f = new class Foo {
> # char[] str () { return s ; }
> # int num () { return n ; }
> # };
> # bar(f);
> # }
> #
> # void main () {
> # func("The answer is", 42);
> # }
>
> I did try your trick of aliasing nested functions into the anonymous
> class' scope... Unfortunatley it didn't work; DMD complained the
> interface was left unimplemented. Not a really big deal, as anonymous
> classes apparently get access to the frame they were created in, the
> same as a delegate does I'd imagine.
That compiles? How weird. I'd expect the assignment to "Foo f" to fail
with a "cannot convert class Foo to interface Foo" type error. Does DMD
simply infer the relationship from the assignment?
Sean
More information about the Digitalmars-d-bugs
mailing list