abstract function templates

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Dec 26 13:45:15 PST 2010


I think this is relevant:
http://www.digitalmars.com/d/2.0/template.html : "Limitations":

Templates cannot be used to add non-static members or virtual
functions to classes.
Templates cannot add functions to interfaces.

But I'm a little confused as to how it all works out. This will work:

import std.stdio;

class Foo
{
    void draw(T)(T t) { writeln("Foo"); };
}

class Bar : Foo
{
    /* override */ void draw(T)(T t) { writeln("Bar"); };
}

void main()
{
    Bar bar = new Bar();
    bar.draw(1); // "Bar"
    (cast(Foo)bar).draw(1); // "Foo"
}

But uncomment the override and it fails.

Experts will have to chime in on this one. :)


More information about the Digitalmars-d-learn mailing list