On Wed, 30 Apr 2014 10:20:22 +0100, Regan Heath <[email protected]> wrote:

Something else to think about.

C# has the same problem and has solved it the following way..

[main.cs]
using ..
using CSTest_Test1;
using CSTest_Test2;

namespace CSTest
{
    class Program
    {
        static void Main(string[] args)
        {
Test1.GetLastError(); // class, not namespace required to call method Test2.GetLastError(); // class, not namespace required to call method
        }
    }
}

[Test1.cs]
using ..
namespace CSTest_Test1
{
    public static class Test1
    {
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern Int32 GetLastError();
    }
}

[Test2.cs]
namespace CSTest_Test2
{
    public static class Test2
    {
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern Int32 GetLastError();
    }
}

GetLastError() is always going to unambiguous here because it *must* live inside a C# class and that class name is *always* required in the call to it.

If D has replaced classes/namespaces with modules, then the answer to our problem may be to use the C++ namespace *only* to mangle the symbol, and *only* use the D module for lookup resolution.

module a;
extern(C++, std) class string {..}

module b:
extern(C++, std) class string {..}
extern(C++, std) class vector {..}

module userland;
import a;
import b;

void main()
{
string x = new string(); //error ambiguous (same resolution as for D symbols)
  a.string x = new a.string(); //ok
  b.vector y = new b.vector(); //ok
}

Regan

Reply via email to