Can't call opIndex on class property

Aho H. Ullman Aho_member at
Tue Apr 4 13:27:25 PDT 2006

In article <e0pmst$1ivn$1 at>, 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.

Maybe resembling the original structure solves your design goal

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

More information about the Digitalmars-d-bugs mailing list