Local static variables must have unique names within a function's scope.

tipdbmp email at example.com
Fri Jan 19 11:02:01 UTC 2018


The following seems to work in C++, but errors in D, why is that?

int foo(int* num) {
     {
         static int x = 10;
         x += 1;
         *num += x;
     }

     {
         static int x = 20; // error: foo.x is already defined in 
another scope in foo
         x += 2;
         *num += x;
     }

     return 0;
}

https://dlang.org/spec/function.html#local-static-variables



More information about the Digitalmars-d-learn mailing list