What does protected mean?
regan at netmail.co.nz
Thu Jul 5 02:00:24 PDT 2007
Kirk McDonald Wrote:
> 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.
To be utterly pedantic; it's only relevant for subclasses in another module, because the ones in the same module have 'friend' access.
More information about the Digitalmars-d-learn