I have a question about static and non-static methods overloading.<br>I have this module:<br><br>--------------------------------------------------------------------------------<br><br>/**<br>  * Dynamic library interfacing module.<br>
  */<br>module dynlib;<br><br>public:<br>    /**<br>      * A lazily loaded cached dynamic library.<br>      */<br>    class DynLib<br>    {<br>    public:<br>        alias void* Symbol;<br>    <br>        /**<br>          * Loads or returns already loaded dynamic library.<br>
          */<br>        static DynLib opIndex(in char[] name)<br>        {<br>            auto lib = name in _libraries;<br>            if(lib)<br>                return *lib;<br>            _libraries[name] = new DynLib(name);<br>
            return DynLib[name];<br>        }<br>        <br>        /**<br>          * Loads or returns already loaded symbol from this dynamic library.<br>          */<br>        Symbol opIndex(in char[] name)<br>        {<br>
            auto sym = name in _symbols;<br>            if(sym)<br>                return *sym;<br>            version(Windows)<br>                _symbols[name] = GetProcAddress(_handle, name.toStringz);<br>            else version(Posix)<br>
                _symbols[name] = dlsym(_handle, name.toStringz);<br>            return DynLib[name];    <br>        }<br>        <br>        bool empty() @property<br>        {<br>            return _handle is null;<br>        }<br>
<br>    private:<br>        alias void* Handle;<br>            <br>        static DynLib[string] _libraries;<br>        static Symbol[string] _symbols;<br>        Handle _handle;<br>        <br>        this(in char[] name)<br>
        {<br>            version(Windows)<br>                _handle = LoadLibraryA(name.toStringz);<br>            else version(Posix)<br>                _handle = dlopen(name.toStringz, RTLD_NOW);<br>        }<br>        <br>
        ~this()<br>        {<br>            version(Windows)<br>                FreeLibrary(_handle);<br>            version(Posix)<br>                dlclose(_handle);<br>        }<br>        <br>        unittest<br>        {<br>
            DynLib dl;<br>            version(Windows)<br>                dl = DynLib["OpenGL32.dll"];<br>            version(Posix)<br>                dl = DynLib["libGL.so"];<br>            assert(!dl.empty);<br>
<br>            DynLib.Symbol sym = dl["glClearColor"];<br>            assert(sym !is null);<br>        }<br>    }<br>    <br>private:<br>    import std.string: toStringz;<br><br>    version(Windows)<br>        import core.sys.windows.windows: LoadLibraryA, FreeLibrary, GetProcAddress;<br>
    else version(Posix)<br>        import core.sys.posix.dlfcn: dlopen, dlclose, dlsym;<br><br>--------------------------------------------------------------------------------<br><br>And when i compile this, i get an unexpected error:<br>
<br>--------------------------------------------------------------------------------<br>
<br>dynlib.d(24): Error: function dynlib.DynLib.opIndex called with argument types:<br>        ((const(char[])))<br>matches both:<br>        dynlib.DynLib.opIndex(in const(char[]) name)<br>and:<br>        dynlib.DynLib.opIndex(in const(char[]) name)<br>
dynlib.d(39): Error: function dynlib.DynLib.opIndex called with argument types:<br>        ((const(char[])))<br>matches both:<br>        dynlib.DynLib.opIndex(in const(char[]) name)<br>and:<br>        dynlib.DynLib.opIndex(in const(char[]) name)<br>
dynlib.d(39): Error: cannot implicitly convert expression (opIndex(name)) of type dynlib.DynLib to void*<br><br>--------------------------------------------------------------------------------<br>
<br>My point is: How can this be ambiguous, when i explicitly call the static method from the class name, not the object and when i call a method from an object, the most obvious choice is the non-static one?<br><br>Cheers,<br>
Gor.<br><br>