On Sunday, 8 November 2020 at 13:10:33 UTC, Adam D. Ruppe wrote:
On Sunday, 8 November 2020 at 10:03:46 UTC, Jan Hönig wrote:
Is there some recourse, which explains the `alias <something>
this`?
If your object is used in a way that doesn't compile, the
compiler will change `obj` to `obj.whatever_alias_this_is` and
try again.
So say you have
struct S {
int a;
alias a this;
}
S obj;
obj += 5;
It will see that obj +=5 doesn't compile on its own, but it has
alias a this so it changes `obj` to `obj.a` and tries again.
So `obj.a += 5;` is the end result.
So it's like inheritance resolved at compile time. It's
inheritance with virtual member functions without overhead.
I am guessing only one alias works.
And we use this, because struct can't do inheritance and
interface is abstract.