Associative Arrays and Structs

Deewiant deewiant.doesnotlike.spam at gmail.com
Sat Mar 17 07:47:54 PDT 2007


Dan wrote:
> For example, if I use Value[char[]], and Value has opCall(int), and I try to:
> 
> Value[char[]] x = 3;
> 
> That will give me an Error: Access Violation.
> But this works:
> 
> Value x = 3;
> 
> I'm assuming I need to do something else for this then, perhaps override opIndex() ?

Not tested, but I think you need to do:

Value[char[]] x;
x["hello"] = Value.init; // or new Value() if Value is a class
x["hello"] = 3;

Or something similar. It seems to me that what happens is that x["hello"] = 3;
is converted into x["hello"].opCall(3); but since the key "hello" doesn't exist
in x, it fails. So you need to init the value first.

-- 
Remove ".doesnotlike.spam" from the mail address.


More information about the Digitalmars-d-learn mailing list