D 中 :: 运算符的等价物是什么?
what is the equivalent of :: operator in D?
我刚刚开始学习 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;
}
如何从 main() 函数中打印全局变量 a 的值? D是否提供这种运营商?
D 使用前导点:
writeln("value of .a is: ",.a);
在规范中:http://dlang.org/module.html - 第 "Module Scope Operator"
部分
我刚刚开始学习 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;
}
如何从 main() 函数中打印全局变量 a 的值? D是否提供这种运营商?
D 使用前导点:
writeln("value of .a is: ",.a);
在规范中:http://dlang.org/module.html - 第 "Module Scope Operator"
部分