writeln the struct from the alis this Example from the home page
Martin Tschierschke
mt at smartdolphin.de
Fri Nov 19 08:44:20 UTC 2021
On Thursday, 18 November 2021 at 16:08:22 UTC, Paul Backus wrote:
> On Thursday, 18 November 2021 at 13:51:42 UTC, Martin
> Tschierschke wrote:
>> [...]
>
> You can define a `toString` method, like this:
>
> ```d
> string toString()
> {
> import std.conv;
> return p.to!string;
> }
> ```
>
> You can find more information about `toString` in the
> documentation here:
> https://dlang.org/phobos/std_format_write.html
>
> By the way, the reason your original version does not work is
> that `p` is `private`, so `writeln` cannot access it. If you
> change `p` to be `public`, it will work without a `toString`
> method.
Thank you, just removing ``private `` and it worked!
More information about the Digitalmars-d-learn
mailing list