digitalmars.D.learn - Protected Members in Class
- Salih Dincer (32/32) Dec 24 2021 What do I need to do to see that the protected is active, need a
- Salih Dincer (12/16) Dec 24 2021 Addition made for one of the inherited class:
- apz28 (3/35) Dec 24 2021 https://dlang.org/spec/attribute.html#visibility_attributes
- Salih Dincer (21/23) Dec 24 2021 Okay, what about the 2nd question (super or this).
- Salih Dincer (4/16) Dec 24 2021 What is the difference between protected and private? Also how
- Paul Backus (6/8) Dec 24 2021 `private` in D means "this symbol can only be accessed from the
- Salih Dincer (2/6) Dec 24 2021 Please, can you show me this?
- Paul Backus (2/8) Dec 24 2021 https://run.dlang.io/is/m1IvVr
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 */ ```
Dec 24 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/classesAddition made for one of the inherited class: ```d override string convertToString() { import std.conv : to; // The swiss army knife of conversion. this.type = "int"; return to!string(type); } ``` The type is not there but it is changed without super! Why? Thanks...
Dec 24 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
Dec 24 2021
On Friday, 24 December 2021 at 10:26:37 UTC, apz28 wrote:https://dlang.org/spec/attribute.html#visibility_attributesOkay, what about the 2nd question (super or this). ```d import app, std.stdio; void main() { auto any = new Any("int"); //any.get().writeln; /* assert(any.data == "int"); /* main.d(7): Error: no property `data` for type `app.Any`, did you mean `app.Any.data`? */ } module app; class Any { protected string data; this(string data) { this.data = data; } property get() { return data; } } ```
Dec 24 2021
On Friday, 24 December 2021 at 11:29:31 UTC, Salih Dincer wrote:```d module app; class Any { protected/* private//*/ string Data; this(string data) { Data = data; } property getData() { return Data; } } string getData(Any test) { return test.Data; } ```What is the difference between protected and private? Also how can a function outside of the class access it? S.Dinçer
Dec 24 2021
On Friday, 24 December 2021 at 12:10:32 UTC, Salih Dincer wrote:What is the difference between protected and private? Also how can a function outside of the class access it?`private` in D means "this symbol can only be accessed from the module where it's defined." `protected` in D means "this symbol can only be accessed from (a) the module where it's defined, and (b) classes that inherit from the class where it's defined."
Dec 24 2021
On Friday, 24 December 2021 at 14:29:29 UTC, Paul Backus wrote:`protected` in D means "this symbol can only be accessed from (a) the module where it's defined, and (b) classes that inherit from the class where it's defined."Please, can you show me this?
Dec 24 2021
On Friday, 24 December 2021 at 15:46:17 UTC, Salih Dincer wrote:On Friday, 24 December 2021 at 14:29:29 UTC, Paul Backus wrote:https://run.dlang.io/is/m1IvVr`protected` in D means "this symbol can only be accessed from (a) the module where it's defined, and (b) classes that inherit from the class where it's defined."Please, can you show me this?
Dec 24 2021