Bug 12469 – opIndex does not work on pointers to structs
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-25T13:30:00Z
Last change time
2014-03-25T13:38:00Z
Assigned to
nobody
Creator
briancschott
Comments
Comment #0 by briancschott — 2014-03-25T13:30:48Z
struct HasOpIndex
{
int opIndex(string s) { return 1; }
}
int main()
{
HasOpIndex* hoi = new HasOpIndex;
return hoi["a"];
}
-----------------
$ rdmd test.d
test.d(5): Error: cannot implicitly convert expression ("a") of type string to ulong
Failed: ["dmd", "-v", "-o-", "test.d", "-I."]
Comment #1 by andrej.mitrovich — 2014-03-25T13:38:00Z
Indexing into pointers is a C feature that was carried over into D. Hence why the compiler expects you to pass a size_t index (ulong on x64). Use (*hoi)["a"] instead.