Should opIndex take precedence over pointer indexing?

claptrap clap at trap.com
Fri Jun 12 23:12:35 UTC 2020


struct Foo
{
     float* what;
     float opIndex(size_t idx) { return what[idx]; }
}

Foo* foo;
float x = foo[idx]; // ***


*** <source>(68): Error: cannot implicitly convert expression 
`foo[cast(ulong)idx]` of type `Foo` to `float`

IE, pointer indexing of 'foo' takes precedence over the opIndex 
of foo. Is this expected?




More information about the Digitalmars-d-learn mailing list