How can one avoid issues using non-primitive static class variables in c++?
<p>I've read quite a bit about initialization of static class variables in c++ and while the google coding standard says only create statics of plain old data (i.e., primitives &amp; pointers), I see quite a few examples online and in books where the authors violate that guideline.</p>

<p>I've also read that as long as you keep the statics in a single compilation unit, that you're less likely to encounter undefined initialization problems.</p>

<p>ok...so having said that...I want some expert opinions on whether or not I will encounter some problems down the road with code that looks like...</p>

<pre><code>//header file snippet
struct TheStruct {
    string theString;
    string theString2;
    float theFloat;
};

class TheClass {
public:
    static const TheStruct Dude;
    static const TheStruct Blah;
    static const TheStruct TheStructArray[];

    TheClass();
    virtual ~TheClass();
    TheStruct getCurrent();
private:
    TheStruct current;
}

//impl file snippet
const TheStruct TheClass::Dude = { "Dude", "Dude", 0 };
const TheStruct TheClass::Blah = { "Blah", "Blah", 0 };
const TheStruct TheClass::TheStructArray[] = {TheClass::Dude, TheClass::Blah};

TheClass::TheClass() : current(TheClass::Dude) {}
TheClass::~TheClass() {}
TheStruct TheClass::getCurrent() {return current;}
</code></pre>

<p>I think the <code>getCurrent()</code> method is ok.  The static const <code>Dude</code> and <code>Blah</code> are wrapped in a static array <code>TheStructArray</code> that something down the road will use.  But, I'm guessing I'm still gonna have the problem with the array if it is used by some other class?  For instance, the array may be used by the GUI to present valid options to choose from.</p>

<p>I come from a Java background, so I have frequently used <code>private static final</code> to define some valid "state"...</p>

<p>Thanks!</p>
