title: Why are "inlined" static consts not allowed, except ints?
body: <blockquote>
    <p><strong>Possible Duplicate</strong><br>
    <a href="https://stackoverflow.com/questions/370283/why-cant-i-have-a-non-integral-static-const-member-in-a-class">Why can&#39;t I have a non-integral static const member in a class?</a></p>
  </blockquote>
  
  <pre><code>struct Example
  {
      static const int One = 1000; // Legal
      static const short Two = 2000; // Illegal
      static const float Three = 2000.0f; // Illegal
      static const double Four = 3000.0; // Illegal
      static const string Five = "Hello"; // Illegal
  };
  </code></pre>
  
  <p><strong>Is there any reason for which #2, #3, #4 and #5 are illegal?</strong></p>
  
  <p>I think I know the reason for #5: the compiler needs a "real" string object (since it's not a built in type) and cannot mindlessy replace <code>Five</code> with <code>"Hello"</code> as if it was <code>#define Five "Hello"</code>. But if that's the case, can't the compiler leave an hint in the .obj files and tell the linker to automatically create one instance of <code>string Five</code> somewhere?</p>
  
  <p>For #3 and #4 and especially #2 (lol!)... I can't really see any possible reason! Floats and doubles are built-in types, just as int is! And short is just a (possibly) shorter integer.</p>
  
  <hr>
  
  <p><strong>EDIT</strong>: I'm using Visual Studio 2008 to compile it. I thought all compilers behaved the same in this case, but apparently g++ compiles that fine (except #5). The errors VS gives for that snippets are:</p>
  
  <pre>
      error C2864: 'Example::Two' : only static const integral data members can be initialized within a class
      error C2864: 'Example::Three' : only static const integral data members can be initialized within a class
      error C2864: 'Example::Four' : only static const integral data members can be initialized within a class
      error C2864: 'Example::Five' : only static const integral data members can be initialized within a class
  </pre>