writeln the struct from the alis this Example from the home page

Steven Schveighoffer schveiguy at gmail.com
Thu Nov 18 20:31:21 UTC 2021


On 11/18/21 2:58 PM, Jordan Wilson wrote:
> 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.
> 
> I thought private was to the module/file, not class/struct?

`writeln` is not in your module.

-Steve


More information about the Digitalmars-d-learn mailing list