[Issue 2417] protected base member is not available via base hanlde in a derived class if it is defined in a separate module

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 17 12:41:49 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2417





------- Comment #3 from schveiguy at yahoo.com  2008-10-17 14:41 -------
It fails because protected does not give access to outside types that are not
of type M2.  the protected attribute is giving access to the derived class ONLY
in the case where the instance IS derived to the same type.

i.e.:

class A
{
   protected byte[] getSecretKey() {return null;}
}

// protect B from being overridden, to protect getSecretKey
final class B : A
{
   protected override byte[] getSecretKey()
   {
     // generate a special key that only classes
     // of type B should know
   }
}

class C : A
{
   byte[] backdoor(A a) { return a.getSecretKey(); }
}

Protected is guaranteeing to class B's author that nobody can get at the
function except for classes that actually derive from B.


-- 



More information about the Digitalmars-d-bugs mailing list