Protected Members in Class

apz28 home at home.com
Fri Dec 24 10:26:37 UTC 2021


On Friday, 24 December 2021 at 08:35:38 UTC, Salih Dincer wrote:
> What do I need to do to see that the protected is active, need 
> a separate module?
>
> ```d
> // Source: https://tour.dlang.org/tour/en/basics/classes
> class Any
> {
>     // protected is just seen by inheriting
>     // classes
>     protected string type;
>
>     this(string type) {
>         this.type = type;
>     }
>
>     // public is implicit by the way
>     string getType() {
>         return type;
>     }
> }
>
> import std.stdio, std.string;
> import std.uni : isWhite;
>
> void main()
> {
>     Any any = new Any("bu bir deneme");
>         any.getType.writeln("--> Split:");
>         any.type.split!isWhite.writeln;
>         any.type = "deneme";
>         any.type.writeln;
> }/* Console Out:
> bu bir deneme--> Split:
> ["bu", "bir", "deneme"]
> deneme
> */
> ```

https://dlang.org/spec/attribute.html#visibility_attributes
#5


More information about the Digitalmars-d-learn mailing list