C++: static vars not persisting between files
<p>I have a config.h file with a bunch of constants.
in main.cpp, it sets one of the constants to some value, and then calls a function in util.cpp.</p>

<p>util.cpp also has config.h included, but the variable set by main.cpp does not have the same value.</p>

<p>Code:</p>

<p>config.h:</p>

<pre><code>static int MAX_NUMBER_OF_TRAINING_DATA = 1000;
</code></pre>

<p>main.cpp (main):</p>

<pre><code>else if (strcmp(argv[i], "-mTrnData") == 0)
            {
                MAX_NUMBER_OF_TRAINING_DATA = atoi(argv[i + 1]);
            cout &lt;&lt; "Number of data sets to be generated: " &lt;&lt; MAX_NUMBER_OF_TRAINING_DATA &lt;&lt; "\n\n";
                          // prints what I tell it
            }
</code></pre>

<p>and in utils.cpp</p>

<pre><code>cout &lt;&lt; "Number of data sets generated: " &lt;&lt; MAX_NUMBER_OF_TRAINING_DATA &lt;&lt; "\n\n";
    // prints the default value (in this case, 1000)
</code></pre>

<p>So, how do I fix this so that I can have my config.h file of constants be remembered throughout my cpp files?</p>

<p>In Java, you can do Config.NAME_OF_CONSTANT , so, if there is a way to do that in C++, that would be most grand.</p>

<p>I know constants aren't supposed to change, but the only time they do change is in main() when reading in the arguments from the running the program... after that they don't change.</p>
