Can't call opIndex on class property
John C
johnch_atms at hotmail.com
Tue Apr 4 15:00:59 PDT 2006
"Aho H. Ullman" <Aho_member at pathlink.com> wrote in message
news:e0ukrd$27ub$1 at digitaldaemon.com...
> In article <e0pmst$1ivn$1 at digitaldaemon.com>, John C says...
>> NameValue pairs() {
>> return pairs_;
>> }
>>but I'd like to keep it as a property.
>
> Properties are defined to be variables or functions, that can be treated
> as
> variables, i.e. functions with at most one argument.
>
> You have two arguments and therefore this is not possible in the current
> version
> of D.
Surely I have no arguments - pairs["Name"] = value should be equivalent to
pairs()["Name"] = value.
>
> Maybe resembling the original structure solves your design goal
No, because I want the 'pairs' property to be read-only - that is, users can
assign values to names, but not override the internal variable.
>
> class Pairs{
> void opIndexAssign(char[] value, char[] name) {
> pairs_[name] = value;
> }
> }
> Pairs pairs;
> this() {
> pairs= new Pairs;
> }
>
> with the call
>
> client.pairs["One"] = "Two"; // no error here
Wait - didn't I already show in my original post that it works if the
variable is used instead?
More information about the Digitalmars-d-bugs
mailing list