I am new to D and have been fiddling with bits and pieces.
I have this code:

import std.stdio : writeln;
import std.format : format;

class Base
{
    override
    {
        //string toString()
        //{
         //   return format("%s", store);
        //}
    }
    ubyte[] store;
    alias store this;
    this()
    {
        store = [1, 2, 3, 4, 5, 6, 7, 8];
    }
}

class Top
{
    Base store;
    alias store this;
    this()
    {
        store = new Base;
    }
}

void main()
{
    auto f = new Top;
    writeln(f.store);
    writeln(f.store);
}

as is it produces:

[1, 2, 3, 4, 5, 6, 7, 8]
[]

I expected it to produce:

[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7, 8]

And with the toString override included it does.

Why does the version without the toString override output an empty array?

Thank you.

Reply via email to