c++ - Can I access static variables inside a function from outside -


c/c++: can access static variables inside function outside? example:

#include <iostream> using namespace std;  void f() {     static int count = 3;     cout << count << endl; }  int main(int argc, char** argv) {     f::count = 5;   // apparently invalid syntax.     f();      return 0; } 

no, can't, neither in c nor in c++.

if want maintain state associated function, define class appropriate state , member function. (in c++. you've tagged question c; same technique works need groundwork yourself.)

although have uses, of time non-const static locals bad idea. make function thread-unsafe, , make "call-once".


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -