Assocative array lookup for object

Chris Katko ckatko at gmail.com
Wed Apr 12 01:16:17 UTC 2023


```D
class bitmapHandler
{
bitmap*[string] bmps;

void get(string name){return bmps[name]; /* plus other code */}
}

void usage()
{
bitmapHandler bh;
bitmap foo = bh.get("bar");  // works
bitmap foo2 = bh["bar"]; // desired
}
```

Should I be using opEquals? Or something different? The problem 
with 'alias this' here is I want to wrap access to the insides 
with getter functions that do various things like logging and 
error checking.

I mean, if I ruined some encapsulation, I could make a function 
called "bh" and have the usage:
```D
bh("bar");
```
and have it access a singleton object.



More information about the Digitalmars-d-learn mailing list