Why is this legal?
rikki cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 29 02:56:34 PDT 2017
On 29/03/2017 10:50 AM, abad wrote:
> This works:
>
> class Foo {
> protected void bar() {
> writeln("hello from foo");
> }
> }
>
> void main() {
> auto foo = new Foo;
> foo.bar();
> }
>
> Is this on purpose and what's the rationale?
http://dlang.org/spec/attribute.html#visibility_attributes
"protected only applies inside classes (and templates as they can be
mixed in) and means that a symbol can only be seen by members of the
same module, or by a derived class. If accessing a protected instance
member through a derived class member function, that member can only be
accessed for the object instance which can be implicitly cast to the
same type as ‘this’. protected module members are illegal."
More information about the Digitalmars-d-learn
mailing list