在D中,:: operator的等价物是什么?

Des*_*tor 6 d global-variables name-lookup

我刚刚开始学习D.在C++中有::(范围解析运算符)从函数中访问全局变量,如果全局和局部变量都具有相同的名称.但是如何用D语言做到这一点?考虑这个计划.

import std.stdio;
int a;
int main(string[] args)
{
    int a=3;
    writeln("D is nice");
    static int i;
    writeln("value of i is: ",i);
    writeln("value of a is: ",a);
   // writeln("value of ::a is: ",::a); compiler error here
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如何从main()函数中打印全局变量a的值?D是否提供这种运营商?

小智 12

D使用一个前导点:

writeln("value of .a is: ",.a);
Run Code Online (Sandbox Code Playgroud)

在规范:http://dlang.org/module.html - "模块范围操作员"部分