Non-covariance and overrides

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sat Sep 7 04:42:49 PDT 2013


On 03/09/13 08:56, Jacob Carlborg wrote:
> class MyFakeSubclass
> {
>      MyBaseClass base
>      alias base this;
> }
>
> Every method not available in MyFakeSubclass will be forwarded to "base".
>
> http://dlang.org/class.html#AliasThis

OK, but the challenge of that approach is that base has to be public, no? 
Otherwise, its methods will not be accessible outside the class (even if the 
alias is itself public).

And that then allows problems inasmuch as the user could then do something like,

     auto foo = new MyFakeSubclass;
     foo.base.bar();

... and so bypass the alias.



More information about the Digitalmars-d-learn mailing list