On Wed, 23 Feb 2011 10:34:04 -0500, spir <[email protected]> wrote:

Hello,

I have read several times that alias this is a way to implement inheritance for structs. I am simply unable to imagine how to use this feature that way. Has anyone an example?

It allows *some* simulation of inheritance. However, it does not implement polymorphism.

What it does is allow specialization and upcasts.  For example:

struct S
{
   int x;
   void foo() {}
}

struct T
{
   S s;
   void foo2() {};
   int y;
   alias s this;
}

T t;
t.foo(); // translates to t.s.foo();
t.x = 5; // translates to t.s.x = 5;
S s = t; // translates to S s = t.s;

-Steve

Reply via email to