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.

6
  • @djf Indeed, maybe that's why I couldn't actually reproduce the error. (But I still think it avoids potential problems to always provide a definition; if not needed the compiler will strip it out anyway. If you want to prevent taking its address you can just use the old enum trick.)
    – gx_
    Commented Jun 6, 2013 at 9:03
  • For completion static const int are treated differently than other data types, see this answer.
    – user2379182
    Commented Jun 6, 2013 at 9:05
  • Isn't MY_CONST defined when you assign it 5? You mean it is "declared to be 5" versus "defined to be 5"? Commented Mar 22, 2016 at 17:09
  • this is the best solution. the suggestion of definition with value only may not fit some situations that value of MY_CONST appears in declaration of other members.
    – ZFY
    Commented Apr 6, 2018 at 14:39
  • This isn't very satisfying. std::min of constant expressions should be evaluated at compile time; if the compiler can't figure out how to do that using static const members, then I'd say static const members aren't ready for prime time and #define MY_CONST 5 is preferable.
    – Don Hatch
    Commented Feb 2, 2019 at 3:46