What does protected mean?

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Jul 4 07:25:16 PDT 2007

Ald wrote:
> I was writing a module with several classes, and found out that classes in the same module can access each other's private methods and even members.
> Is this by design?  If so, then what is protected modifier for?  I have read the manual, but didn't understand the difference.

Yes: Everything in the same module has an implicit "friend" 
relationship, and they can access each other's private stuff. This is 
entirely by design, and replaces C++'s explicit "friend" stuff.

Otherwise, protected means what it does in many other languages. If 
something is private, then nothing outside the class (except for things 
in the same module) can access it, not even subclasses of the class. 
Protected, on the other hand, is just like private, except it grants 
access to subclasses.

Kirk McDonald
Pyd: Connecting D and Python

More information about the Digitalmars-d-learn mailing list