Old problem with performance

dsimcha dsimcha at yahoo.com
Sun Feb 8 16:27:26 PST 2009


== Quote from Derek Parnell (derek at psych.ward)'s article
> This is what I thought too. In D, a value type can be derived from another
> value type by using a combination of data aggregation (data inheritance if
> you will) and interface aggregation (method inheritance?).
> I feel that D could do with a little more syntax support for derived value
> types though, because at times it is a bit awkward and/or verbose. I'll dig
> up some examples of what I mean.

In D2, you could try aggregation and opDot() w/ ref return.  See
http://digitalmars.com/d/2.0/operatoroverloading.html#Dot .  That pretty much
simulates a form of inheritance w/o polymorphism.

struct Foo {
    int i;

    void doStuff() {
        // Do stuff.
    }
}

struct Bar {
    private Foo foo;

    ref Foo opDot() {
        return foo;
    }
}

void main() {
    Bar bar;
    bar.doStuff();  // Calls Bar.foo.doStuff().
}

One caveat, though, is that operator overloading behaves weirdly w/ this.  See bug
2327:  http://d.puremagic.com/issues/show_bug.cgi?id=2327



More information about the Digitalmars-d mailing list