"alias that this" or "alias this : that"

Nick Treleaven ntrel-public at yahoo.co.uk
Thu Feb 13 04:56:45 PST 2014


On 08/02/2014 13:43, Timon Gehr wrote:
> class C{
>      this(int x){ ... }
>      ...
> }
>
> class D: C{
>      alias this = super; // (inherit constructors)
>      this(double y){ ... } // (overload with a new constructor)
> }

That syntax is indeed confusing if we also had 'alias this : baz' 
syntax, because it looks quite like you're saying instances of D convert 
automatically to an instance of C, which is implicit OOP anyway and 
makes that statement look redundant.

That is not the suggested syntax that causes the conflict. Forwarding 
constructors would be done like this:

class D: C{
	alias this = super.this;
}

The idea is that 'alias foo = bar' syntax introduces a new symbol called 
'foo'.

For the record, constructor forwarding is just an idea I discussed with 
Kenji, not something that has been accepted necessarily.


More information about the Digitalmars-d mailing list