About Store Forum Documentation Contact



Post Reply 
Global Static
Author Message
Rubeus Offline
Member

Post: #1
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
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
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
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
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
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #4
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. smile
05-26-2014 09:47 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #5
RE: Global Static
Rubeus: Whoops. I've been solely using C# for years now. You can't use global static there. pfft

C++ is becoming a bit of a blur sometimes. :(
05-27-2014 08:14 AM
Find all posts by this user Quote this message in a reply
Post Reply