www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Logging inside struct?

reply biocyberman <biocyberman gmail.com> writes:
How do I add logging for this struct?

https://run.dlang.io/is/9N6N4o

If not possible, what's the alternative?
May 30 2018
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Wednesday, 30 May 2018 at 09:58:16 UTC, biocyberman wrote:
 How do I add logging for this struct?

 https://run.dlang.io/is/9N6N4o

 If not possible, what's the alternative?
This line: writeln("got num: %s, of type: %s", num, typeof(num)); Gives this error message: onlineapp.d(7): Error: cannot pass type int as a function argument The error message says exactly what's wrong - you can't pass a type as a runtime argument. You can get a string representation using .stringof: writeln("got num: %s, of type: %s", num, typeof(num).stringof); Next up: if prints this: got num: %s, of type: %s1int 1 You probably want something more like this: got num: 1, of type: int 1 The problem is you're using writeln, which only dumps its arguments to stdout in the order they're passed. writefln does formatting using %s: writefln("got num: %s, of type: %s", num, typeof(num).stringof); -- Simen
May 30 2018
parent biocyberman <biocyberman gmail.com> writes:
On Wednesday, 30 May 2018 at 10:07:35 UTC, Simen Kjærås wrote:
 On Wednesday, 30 May 2018 at 09:58:16 UTC, biocyberman wrote:
 [...]
This line: writeln("got num: %s, of type: %s", num, typeof(num)); [...]
Problem solved. Thanks Simen!
May 30 2018