Skip to content

Access violation #13

@bioinfornatics

Description

@bioinfornatics

they are a problem around private var, below code:

private import std.array    : split;
private import std.stdio    : writeln;
private import std.string   : format, stripLeft, stripRight;

class Container{
    private:
        string[string] dict;
        string name;
    this( string name ){
        this.name = name;
        this.dict = dict;
    }
}
void main( string[] args ){
    string[]words = split(cast(string)"key=value", "=");
    foreach( ref string word; words )
        word.stripRight().stripLeft();

    Container c = new Container("test");
    c.dict[words[0]] = words[1];
    writeln( "strange access to private var!!!" );
    writeln( c.dict );
    writeln( c.dict["key"] );
    writeln( c.dict.keys );
}

poduce this output:

$ ldc2 test.d
$ ./test
strange access to private var!!!
["key":"value"]
value
["key"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions