// Two simple value type structures. one embedded in the other. I've stepped through the debugger and I see the embedded structure being set to 2, and dog.



import std.stdio;

struct NestedBottom
{
    int i;
    char[3] fixedArray;
// this(){} no-argument ctor can only be defined by the compiler
    this(int i, char[3] fixedArray)
    {
        this.i = i;
        this.fixedArray = fixedArray;
    }
    void print()
    {
        writeln("This is level ", i);
        writeln("animal = ", fixedArray);
    }
}

struct NestedTop
{
    int i;
    char[3] fixedArray;
    NestedBottom bottom;
// this(){} no-argument ctor can only be defined by the compiler
    this(int i, char[3] fixedArray)
    {
        this.i = i;
        this.fixedArray = fixedArray;
        auto bottom = NestedBottom(2, ['d','o','g']);
    }
    void print()
    {
        writeln("This is level ", i);
        writeln("animal = ", fixedArray);
        bottom.print();

        // added this in desperation. Still nothing.
        writeln("This is level ", bottom.i);
        writeln("animal = ", bottom.fixedArray);
    }
}


void main()
{
    auto top = NestedTop(1, ['c', 'a', 't']);
    top.print();
}



Output is the following:

This is level 1
animal = cat
This is level 0
animal =
This is level 0
animal =


Reply via email to