January 24, 2006
In the spec on mixins (http://www.digitalmars.com/d/mixin.html) it states "Mixins can add virtual functions to a class". The following shows this to be true:

    template Virtuals {
        void test() { printf("Virtuals.test");
    }

    class Target {
        mixin Virtuals;
        void test() { printf("Target.test");
    }

    Target t = new Target;
    t.test(); // prints "Target.test"

However, it the virtual mechanism breaks down when using interfaces:

    interface ITarget {
        void test();
    }

    class Target : ITarget {
        mixin Virtuals;
        void test() { printf("Target.test");
    }

    ITarget t = new Target;
    t.test(); // prints "Virtuals.test"

I would expect the above line to print "Target.test" as in the first examples.

John.


January 25, 2006
John C schrieb am 2006-01-24:
> In the spec on mixins (http://www.digitalmars.com/d/mixin.html) it states "Mixins can add virtual functions to a class". The following shows this to be true:
>
>     template Virtuals {
>         void test() { printf("Virtuals.test");
>     }
>
>     class Target {
>         mixin Virtuals;
>         void test() { printf("Target.test");
>     }
>
>     Target t = new Target;
>     t.test(); // prints "Target.test"
>
> However, it the virtual mechanism breaks down when using interfaces:
>
>     interface ITarget {
>         void test();
>     }
>
>     class Target : ITarget {
>         mixin Virtuals;
>         void test() { printf("Target.test");
>     }
>
>     ITarget t = new Target;
>     t.test(); // prints "Virtuals.test"
>
> I would expect the above line to print "Target.test" as in the first examples.
>
> John.

Added to DStress as http://dstress.kuehne.cn/run/m/mixin_15_A.d http://dstress.kuehne.cn/run/m/mixin_15_B.d http://dstress.kuehne.cn/run/m/mixin_15_C.d

Thomas