Low-overhead components

Faux Amis faux at amis.com
Tue Jul 30 07:33:51 PDT 2013


On 30-7-2013 14:48, Dicebot wrote:
> On Tuesday, 30 July 2013 at 12:37:26 UTC, Faux Amis wrote:
>> I do not understand what this code should help with:
>>
>> struct LAYER(BASE)
>> {
>>     BASE base;
>>     // ... use base ...
>> }
>>
>> Any advice on what I should read to get it?
>> (no C++ exp)
>
> It is meant to do "has-a" (http://en.wikipedia.org/wiki/Has-a)
> inheritance with only exception - it should not be as is not an
> inheritance. :) Common way to achieve code re-usage without defining
> meaningless hierarchies.

like this:?

struct LAYER(BASE)
{
	BASE base;
	// ... use base ...
	void func(){};
}

struct Base
{
	alias LAYER!(Base) Layer;
	Layer layer;
	layer.base = this;
	layer.func();
     // ...
}


More information about the Digitalmars-d mailing list