Bug with multiple subtyping?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sat Sep 7 07:10:31 PDT 2013


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inherit.d
Type: text/x-dsrc
Size: 133 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130907/6ade8432/attachment.d>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inheritance.d
Type: text/x-dsrc
Size: 366 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130907/6ade8432/attachment-0001.d>


More information about the Digitalmars-d-learn mailing list