Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

13
  • 9
    Things are different in c++11. Answer could use updating.
    – bames53
    Commented Apr 9, 2012 at 6:06
  • 4
    This doesn't seem to be true : "Note that only static const integers can be treated as compile time constants. The compiler knows that the integer value will not change anytime and hence it can apply its own magic and apply optimizations, the compiler simply inlines such class members i.e, they are not stored in memory anymore," Are you sure they're necessarily not stored in memory? What if I provide definitions for the members? What would &member return? Commented May 18, 2012 at 6:22
  • 4
    @Nawaz: Because C++03 only allowed constant-initializer for static and const integral and const enumeration type and no other type, C++11 extends this to an const literal type which relaxes the norms for In-Class Initialization.The limitation in C++03 was perhaps a oversight which warranted a change and hence was corrected in C++11, if there are any traditional tactical reasons for the change I am not aware of them.If you are aware of any feel free to share them.
    – Alok Save
    Commented May 18, 2012 at 6:41
  • 4
    The "Workaround" par you mentioned is not working with g++.
    – iammilind
    Commented Oct 11, 2012 at 9:57
  • 5
    So just to confirm... What we're saying is: (1) It's that way because the C++03 language standard says it's that way; (2) there's no underlying logical reason it should be that way; (3) it's fixed in C++11. Commented Oct 18, 2012 at 20:44