[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 13:43:28 PDT 2008


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





------- Comment #5 from schveiguy at yahoo.com  2008-10-17 15:43 -------
(In reply to comment #4)
> When you want to do this, there is no really reasonable way around it.  You
> make the method protected, subclasses can't call it.

Yes they can, they can call it on their own instance, or on instances of the
same class.  i.e. the following should work:

if(auto x = cast(M2)m1)
{
   x.foo();
}

> You make it private, no
> one can call it.  You make it package, only classes at the same level in the
> package hierarchy can call it.  You make it public, anyone can call it.  There
> is no good solution.  There is no way to say "this method can be overridden or
> called from derived classes and nowhere else,"

What you are asking for is 'overridden or called from any class that derived
from my base class'.  Protected functions already can be called from derived
classes in their own instance or in instances of their own type.  Another class
may not want you to be able to call their protected function simply by
inheriting its base class.

If we listed all the 'protection schemes' that people wanted, I'm sure there
would be at least a dozen.  Should all these be implemented?


-- 



More information about the Digitalmars-d-bugs mailing list