Logging inside struct?
Simen Kjærås
simen.kjaras at gmail.com
Wed May 30 10:07:35 UTC 2018
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
More information about the Digitalmars-d-learn
mailing list