On 2013-09-07 13:42, Joseph Rushton Wakeling wrote:
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.


I haven't checked if "base" can be private or not. But if that doesn't work try opDispatch:

http://dlang.org/operatoroverloading.html#Dispatch

You have a public opDispatch and a private "base".

--
/Jacob Carlborg

Reply via email to