Why do I have to cast arguments from int to byte?
Chirs Forest
CF at chrisforest.com
Tue Oct 10 19:55:36 UTC 2017
I keep having to make casts like the following and it's really
rubbing me the wrong way:
void foo(T)(T bar){...}
byte bar = 9;
foo!byte(bar + 1); //Error: function foo!byte.foo (byte bar) is
not callable using argument types (int)
foo!byte(cast(byte)(bar + 1));
It wouldn't be so bad if I didn't have to use the word cast
before each cast, bust since I have to specify both the word cast
and the cast type and then wrap both the cast type and the value
in brackets... it just explodes my code into multiple lines of
unreadable mess.
void foo(T)(T bar, T bar2, T bar3){...}
byte foobar = 12;
foo!byte(foobar + 1, foobar + 22, foobar + 333);
vs.
foo!byte(cast(byte)(foobar + 1), cast(byte)(foobar + 22),
cast(byte)(foobar + 333));
Why?
More information about the Digitalmars-d-learn
mailing list