Rubeus
Member
|
Global Static
When declaring a static variable in the Namespace scope, the editor tells me:
Error: Invalid "static" keyword for global variable/function.
Additionally, while this message is present, it does not open Visual Studio. It looks as if this is meant to strongly discourage this combination of scope and keyword, despite it being legal and valid in C++.
Is there a reason for this? My goal was to have a global variable, but without being linked to other files. It's not crucial(just a way to keep things cleaner), but I was curious about the strange behavior.
(This post was last modified: 05-26-2014 09:11 PM by Rubeus.)
|
|
05-26-2014 09:10 PM |
|
Tottel
Member
|
RE: Global Static
If you're making a variable global (not part of a class), there is no point in using the "static" keyword. It's already accessible everywhere.
The use of static that you are thinking of, is to make a variable global across all objects of the same class.
|
|
05-26-2014 09:17 PM |
|
Esenthel
Administrator
|
RE: Global Static
In code editor global static is not supported because global variables are always visible to other files
|
|
05-26-2014 09:44 PM |
|
Rubeus
Member
|
RE: Global Static
Oh, ok - so it's just there to prevent bugs with the editor, then. It will work just as well inside my function, so I'll do that.
Tottel, static has a different meaning when global. It becomes less accessible.
|
|
05-26-2014 09:47 PM |
|
Tottel
Member
|
RE: Global Static
Rubeus: Whoops. I've been solely using C# for years now. You can't use global static there.
C++ is becoming a bit of a blur sometimes. :(
|
|
05-27-2014 08:14 AM |
|