Is there any good reason why C++ namespaces are "closed" in D?
Walter Bright
newshound2 at digitalmars.com
Mon Jul 30 20:05:27 UTC 2018
On 7/30/2018 7:20 AM, Atila Neves wrote:
>> ------
>> extern (C++, ns) { int foo() { return 1; } }
>>
>> mixin template X()
>> {
>> extern (C++, ns) { int bar() { return 2; } }
>> }
>>
>> mixin X!() x;
>>
>> -------
>
> void main() {
> pragma(msg, __traits(allMembers, ns));
> foo;
> bar;
> }
>
> $ dmd foo.d
> tuple("foo")
> foo.d(15): Error: undefined identifier bar
>
> That method doesn't compile.
You'll need to add:
alias bar = x.bar;
which will add bar to the current scope.
> foo.o:foo.d:function _Dmain: error: undefined reference to 'S::ns::bar()'
Hmm, when I tested it the 'S::' prefix wasn't there. But when I retested it, it
was. (!) I'll look into this.
More information about the Digitalmars-d
mailing list