Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the equivalent of :: operator in D?

I've just started learning D. In C++ there is :: (Scope resolution operator) to access global variable from the function if both global & local varible have same name. But how to do this in D language? Consider this program.

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;
}

How can I print the value of global variable a from within main() function? Does D provide such kind of operator?

like image 929
Destructor Avatar asked Aug 04 '15 10:08

Destructor


People also ask

What is the name of :: operator?

It's called scope resolution operator. More information in Scope Resolution Operator (::) (PHP manual).

What is the use of :: operator?

In C++, scope resolution operator is ::. It is used for following purposes. 2) To define a function outside a class. 3) To access a class's static variables.

What does :: operator mean in Java?

An operator, in Java, is a special symbols performing specific operations on one, two or three operands and then returning a result. The operators are classified and listed according to precedence order. Java operators are generally used to manipulate primitive data types.

What is :: operator in Scala?

The ::() operator in Scala is utilized to add an element to the beginning of the List. Method Definition: def ::(x: A): List[A] Return Type: It returns the stated list after adding an element to the beginning of it.


1 Answers

D uses a leading dot for that:

writeln("value of .a is: ",.a);

In the spec: http://dlang.org/module.html - section "Module Scope Operator"

like image 197
user5189294 Avatar answered Sep 26 '22 19:09

user5189294