FreeSlave:

By the way, why does writeln able to print this struct? It has no toString() method and its data is private. How does writeln have access to it?

writeln is able to print structs that don't have a toString, this is very handy in most cases. When you don't want it, there's @disable, this doesn't link:

struct Foo {
    int x;
    //string toString() { return "x"; }
    @disable string toString();
}

void main() {
    import std.stdio;
    Foo f = Foo(10);
    writeln(f);
}


In theory this should be caught by writefln constraint before the linker. Probably I can turn this into a small enhancement request.

Bye,
bearophile

Reply via email to