Static variable definition order in c++
<p>Hi i have a class tools which has static variable std::vector m_tools. </p>

<p>Can i insert the values into the static variable from Global scope of other classes defined in other files. </p>

<p>Example: </p>

<p>tools.h File </p>

<pre><code>class Tools
{
public:
static std::vector&lt;std::vector&gt; m_tools;

void print()
{
for(int i=0 i&lt; m_tools.size() ; i++)
std::cout&lt;&lt;"Tools initialized :"&lt;&lt; m_tools[i];
}
}
</code></pre>

<p>tools.cpp File</p>

<pre><code>std::vector&lt;std::vector&gt; Tools::m_tools;  //Definition
</code></pre>

<p>Using register class constructor for inserting the new string into static variable.</p>

<pre><code>class Register
{
public:
  Register(std::string str)
{
Tools::m_tools.pushback(str);
}

};
</code></pre>

<p>Different class which inserts the string to static variable in static variable</p>

<p>first_tool.cpp</p>

<pre><code>//Global scope declare global register variable


Register a("first_tool");



////////
</code></pre>

<p>second_tool.cpp</p>

<pre><code>//Global scope declare global register variable


Register a("second_tool");
</code></pre>

<p>Main.cpp</p>

<pre><code>void main()
{
Tools abc;
abc.print();
}
</code></pre>

<p>Will this work?</p>

<p>In the above example on only one string is getting inserted in to the static list. Problem look like "in Global scope it tries to insert the element before the definition is done"
Please let me know is there any way to set the static definiton priority? Or is there any alternative way of doing the same.</p>
