On Sunday, 12 May 2013 at 11:21:16 UTC, Temtaime wrote:
Hello to all !
I'm surprised that there is no structure's inheritance.

There is a problem:
I want to make Matrix MxN class. I also want to make child classes Square Matrix and Vector from it with additional functions. I don't want use "class" cause of "new" overhead. Std typecons's Scoped - workaround with many restrictions, so it isn't true solution.

I'm tried mixin template but there is no luck. I don't know how to declare multiplication operator for example.

Any suggestions ?
Regards.

You could make the base struct a member of the child struct and refer with alias this Base; to the base:

[code]
import std.stdio;

struct A {
public:
        int id;
}

struct B {
public:
        A hidden_a;
        alias hidden_a this;

        int age;

        this(int id, int age) {
                this.age = age;
                this.id = id;
        }
}

void main() {
        B b = B(42, 23);
        writefln("Person #%d is %d years old.", b.id, b.age);
}
[/code]

Reply via email to