digitalmars.D.learn - What does protected mean?
- Ald (2/2) Jul 04 2007 I was writing a module with several classes, and found out that classes ...
- Kirk McDonald (14/17) Jul 04 2007 Yes: Everything in the same module has an implicit "friend"
- Regan Heath (3/17) Jul 05 2007 To be utterly pedantic; it's only relevant for subclasses in another mo...
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.
Jul 04 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 http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Jul 04 2007
Kirk McDonald Wrote:Ald wrote:To be utterly pedantic; it's only relevant for subclasses in another module, because the ones in the same module have 'friend' access. ReganI 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.
Jul 05 2007