Why can't I inherit (extend) structs?

rm roel.mathys at gmail.com
Tue Oct 10 13:38:22 PDT 2006


Lionello Lunesu wrote:
> It's not a big deal, since I can use composition

but mixin' it in, works nicely

rm

=========================================

private import std.stdio;

template XT()
{
	struct
	{
		int x;
	}
}

struct X
{
	mixin XT;
}

struct Z
{
	mixin XT;
	int z;
}

void main()
{
	X x;
	x.x = 5;
	writefln(x.x);
	Z z;
	z.x = 1;
	z.z = 2;
	writefln(z.x,' ',z.z);
}



More information about the Digitalmars-d-learn mailing list