title: C++11 Initializing class static const array
body: <p>Here's what I am trying. MinGW g++ 4.7.0.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class Fruit
  {
  public:
      enum Value { APPLE, ORANGE, BANANA, NONE };
      static const Value VALUES[4] = { APPLE, ORANGE, BANANA, NONE };
      Fruit (Value v = NONE) : v_(v) { };
      std::string to_string () const {
          switch (v_) {
              case APPLE: return "apple";
              case ORANGE: return "orange";
              case BANANA: return "banana";
              default: return "none";
          }
      }
  private:
      Value v_;
  };
  
  int main (int argc, char * argv[])
  {
      for (Fruit f : Fruit::VALUES)
          std::cout &lt;&lt; f.to_string() &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>I try compiling it and get the output below:</p>
  
  <pre><code>&gt;g++ -std=c++0x test.cpp
  test.cpp:9:66: error: 'constexpr' needed for in-class initialization of static d
  ata member 'const Fruit::Value Fruit::VALUES [4]' of non-integral type [-fpermis
  sive]
  
  
  &gt;g++ -std=c++0x -fpermissive test.cpp
  test.cpp:9:66: warning: 'constexpr' needed for in-class initialization of static
   data member 'const Fruit::Value Fruit::VALUES [4]' of non-integral type [-fperm
  issive]
  cc1l4Xgi.o:test.cpp:(.text+0x1a): undefined reference to `Fruit::VALUES'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>Is C++11 supposed to allow initializing a static const array in a class like this? Or does it have to be defined outside the class as before C++11?</p>