Bug with multiple subtyping?

Jacob Carlborg doob at me.com
Sun Sep 8 12:44:02 PDT 2013


On 2013-09-07 16:10, Joseph Rushton Wakeling wrote:
> Hello all,
>
> TDPL gives a description in Section 6.13 (pp. 230-233) of a method for
> subtyping by storing a private instance of the base type and using
> "alias ... this" to access its methods.  The example given is as follows:
>
> class StorableShape : Shape
> {
>      private DBObject _store;
>      alias _store this;
>
>      this()
>      {
>          _store = new DBObject;
>      }
> }
>
> However, I've found that this won't work because the "private" keyword
> means that functions and objects outside the module won't be able to
> access the public methods of _store, even though the alias itself is
> public.
>
> I've attached a small example with 2 classes, A and B, where B stores an
> internal copy of A in a similar manner.  In this case, if you run rdmd
> inherit.d, you'll get an error:
>
>    inherit.d(8): Error: class inheritance.B member base is not accessible
>
> Is this a bug, or intentional, and if it's intentional, how can one make
> the public methods of the "base" class accessible while keeping the
> instance private?
>
> Thanks & best wishes,
>
>      -- Joe

Try using opDispatch as a described in the other thread.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list