what is the equivalent of :: operator in D?

Destructor

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?

user5189294

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"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the equivalent of :: operator in java?

From Dev

what is the equivalent of += operator in clojure

From Dev

What is the BINARY operator equivalent in JPQL?

From Dev

What is the JavaScript equivalent for Swift ?? operator

From Dev

What is the BINARY operator equivalent in JPQL?

From Java

What is the equivalent of the join operator over a vector of Strings?

From Dev

What is the Python numpy equivalent of the IDL # operator?

From Dev

What's the equivalent of a spread operator (...) for objects properties?

From Dev

What is the equivalent of the "is" operator for reflected generic types?

From Dev

The &= Operator Equivalent

From Java

What is the idiomatic Go equivalent of C's ternary operator?

From Dev

What's the JavaScript equivalent of Ruby's splat operator?

From Dev

What's Irony's equivalent of Yacc's optional operator ("?")?

From Dev

What's the JavaScript equivalent of Ruby's splat operator?

From Dev

What's the equivalent of mysql RLIKE operator in Hibernate Query?

From Dev

Inequality operator(!= equivalent) in swift

From Dev

Python equivalent of the R operator "%in%"

From Dev

Equivalent of comma operator in MATLAB?

From Dev

Kotlin equivalent of ternary operator

From Dev

numpy array equivalent for += operator

From Dev

ElasticSearch : IN equivalent operator in ElasticSearch

From Dev

Ruby equivalent to JavaScript operator `||`

From Dev

Is there a spread operator equivalent in Powershell?

From Dev

ternary conditional operator equivalent?

From Dev

What is the ruby equivalent of this java loop since there's no pre-increment operator?

From Dev

What would be the MongoDB C# driver equivalent of the following query using the array update operator $[<identifier>]

From Dev

What is the equivalent of Mathematica's RegionPlot3D[] in MATLAB?

From Dev

What is the FreeBSD equivalent of Linux update-rc.d?

From Dev

What is the Linux equivalent of C drive on SSD and D drive on HDD?

Related Related

  1. 1

    What is the equivalent of :: operator in java?

  2. 2

    what is the equivalent of += operator in clojure

  3. 3

    What is the BINARY operator equivalent in JPQL?

  4. 4

    What is the JavaScript equivalent for Swift ?? operator

  5. 5

    What is the BINARY operator equivalent in JPQL?

  6. 6

    What is the equivalent of the join operator over a vector of Strings?

  7. 7

    What is the Python numpy equivalent of the IDL # operator?

  8. 8

    What's the equivalent of a spread operator (...) for objects properties?

  9. 9

    What is the equivalent of the "is" operator for reflected generic types?

  10. 10

    The &= Operator Equivalent

  11. 11

    What is the idiomatic Go equivalent of C's ternary operator?

  12. 12

    What's the JavaScript equivalent of Ruby's splat operator?

  13. 13

    What's Irony's equivalent of Yacc's optional operator ("?")?

  14. 14

    What's the JavaScript equivalent of Ruby's splat operator?

  15. 15

    What's the equivalent of mysql RLIKE operator in Hibernate Query?

  16. 16

    Inequality operator(!= equivalent) in swift

  17. 17

    Python equivalent of the R operator "%in%"

  18. 18

    Equivalent of comma operator in MATLAB?

  19. 19

    Kotlin equivalent of ternary operator

  20. 20

    numpy array equivalent for += operator

  21. 21

    ElasticSearch : IN equivalent operator in ElasticSearch

  22. 22

    Ruby equivalent to JavaScript operator `||`

  23. 23

    Is there a spread operator equivalent in Powershell?

  24. 24

    ternary conditional operator equivalent?

  25. 25

    What is the ruby equivalent of this java loop since there's no pre-increment operator?

  26. 26

    What would be the MongoDB C# driver equivalent of the following query using the array update operator $[<identifier>]

  27. 27

    What is the equivalent of Mathematica's RegionPlot3D[] in MATLAB?

  28. 28

    What is the FreeBSD equivalent of Linux update-rc.d?

  29. 29

    What is the Linux equivalent of C drive on SSD and D drive on HDD?

HotTag

Archive