Is there a way to remove the requirement for parenthesis?
Charles Hixson
charleshixsn at earthlink.net
Wed Jan 21 09:24:01 PST 2009
In this test I'm trying to emulate how I want a typedef to act, but I
run into a problem:
import std.stdio;
struct BlockNum
{ uint value;
uint opCast() { return value; }
void opAssign (uint val) { value = val; }
uint opCall() { return value; }
}
void main()
{ BlockNum test;
test = 42;
uint tst2 = test(); // <<== if I don't have the parenthesis I
// get a compiler error (cast
// required).
// kfile.d(15): Error: cannot implicitly convert expression
// (test) of type BlockNum to uint
writef ("tst2 = %d\n", tst2);
}
It seemed to me as if the parens shouldn't be required here, but I seem
mistaken. Which leads to ugly code. Is there a way around this?
More information about the Digitalmars-d-learn
mailing list