13 with programmed values d and reference types

Value type is copied entity.
Reference type is the key. I think, why not &table reference it? Too strange.
Reference variables as the key, not the entity can access.
D class is a reference type. Copy of a class variable when you get a key. the key to change the value of the back, in front of the entity has changed. unless you and assign a new entity.
also, when assigning associative array, is the same, just as single cases, unless you're a new assignment an entity, you actually copy is a key.

    auto variable = new MyClass;
    variable.member = 1;

    auto variable2 = variable;   //还是那个
    variable2.member = 2;
    assert(variable.member == 2); //原来那个改了
//-----
 string[int] byName =
    [
        1   : "one",
        10  : "ten",
        100 : "hundred",
    ];

    string[int] byName2 = byName;//得到新钥匙

    byName2[4] = "four";//改了.

    assert(byName[4] == "four");//原来的实体也改了

But you copied 钥匙very powerful. You can modify fucks Scrapped.
Slice, there are two types, one is the key one is the entity that is the key to slice some copy to get a key to start work a.

    int[] slice1 = [ 10, 11, 12, 13, 14 ];
    int[] slice2 = [ 20, 21, 22 ];
    int[] slice3 = slice1[1 .. 3];
//干坏事的钥匙,破坏1切片
    slice3[0] = 777;
    assert(slice1 == [ 10, 777, 12, 13, 14 ]);
    slice3 = slice2[$ - 1 .. $];
//干坏事的钥匙,破坏2切片
    slice3[0] = 888;
    assert(slice2 == [ 20, 21, 888 ]);
//同样的,搞破坏.
 auto variable1 = new MyClass;
    variable1.member = 1;

    auto variable2 = new MyClass;
    variable2.member = 2;

    auto aCopy = variable1;
    aCopy.member = 3;

    aCopy = variable2;
    aCopy.member = 4;

    assert(variable1.member == 3);
    assert(variable2.member == 4);

Thus:
MyClass variable;for the 无效null reference in this case the class is not yet created. 空指针
Fixed-length array is a value type 切片is a reference type (with a key / min entities).

    int[3] array1 = [ 10, 20, 30 ];
    auto array2 = array1; //复制实体,
    array2[0] = 11;
    assert(array1[0] == 10);//未受影响

Module variable, the whole module can access global variables. In addition to all functions.
Reference types can be 无效that one who has not yet explained the key points.

Published 381 original articles · won praise 25 · Views 100,000 +

Guess you like

Origin blog.csdn.net/fqbqrr/article/details/104587382