Thread overview
Protected Members in Class
Dec 24, 2021
Salih Dincer
Dec 24, 2021
Salih Dincer
Dec 24, 2021
apz28
Dec 24, 2021
Salih Dincer
Dec 24, 2021
Salih Dincer
Dec 24, 2021
Paul Backus
Dec 24, 2021
Salih Dincer
Dec 24, 2021
Paul Backus
December 24, 2021

What do I need to do to see that the protected is active, need a separate module?

// 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
*/
December 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?

// Source: https://tour.dlang.org/tour/en/basics/classes

Addition made for one of the inherited class:

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...

December 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?

// 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

December 24, 2021

On Friday, 24 December 2021 at 10:26:37 UTC, apz28 wrote:

>

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

Okay, what about the 2nd question (super or this).

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; }
}

December 24, 2021

On Friday, 24 December 2021 at 11:29:31 UTC, Salih Dincer wrote:

>
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

December 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."

December 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?

December 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:

>

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?

https://run.dlang.io/is/m1IvVr