On Wed, 21 Jan 2009 20:26:08 +0300, Charles Hixson <charleshi...@earthlink.net>
wrote:
P.S.: This is Digital Mars D Compiler v2.023 running on Linux
Charles Hixson wrote:
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?
No, there isn't. It leads to ambiguity and here is why:
class Foo
{
Foo opCall() { return new Foo(); }
}
void main() {
Foo bar = new Foo();
auto ambiguous = bar; // is it 'bar' or 'bar()'?
}
One more case where empty pair of parens is mandatory.
To Walter & Co: Please, oh *PLEASE* drop this feature and give us real
properties!