extern(C++, ns)

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 8 05:50:56 PST 2016


On 1/8/2016 12:11 AM, Jacob Carlborg wrote:
> Walter, should "ns.a()" work in the above example?

No:

1. first "ns.a" looks up "ns". Finds it in the current module, "main.ns".
2. Looks "a" up in "main.ns". "a" is not there. Error.

"a()" works because:

1. Look up "a" in current module. Doesn't find it.
2. Look up "a" in import "foo".
    1. doesn't find it. Look in imported scope "foo.ns". finds it.
3. Look up "a" in import "bar".
    1. doesn't find it. Look in imported scope "bar.ns". Doesn't find it.

Found only one "a" in the imports. We have da winnah!

I think name lookup rules are straightforward in D. I explain them over and 
over, for years, and nobody but me understands them. I find it very frustrating.


More information about the Digitalmars-d mailing list