www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12469] New: opIndex does not work on pointers to structs

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12469

           Summary: opIndex does not work on pointers to structs
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: brian-schott cox.net



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."]

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 25 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12469


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |INVALID



21:38:00 CET ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 25 2014