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.

9
  • 4
    They are const now -- they just need to be static as well so that I can use them in static member functions. What's the reason for that rule that they must be declared inside and defined outside a class? That doesn't make much sense to me. Commented Feb 16, 2011 at 17:37
  • 3
    @Felix Dombek: I think the reason is that the class is(/could be) declared for each source file you compile and link, but the actual variables must be only defined once. That's the same reason you need to explicitly declare as extern the variables defined in other source files. Commented Feb 16, 2011 at 17:40
  • 2
    @peoro: That seems reasonable! But then why is it allowed for integral datatypes? That shouldn't be allowed either, then ... Commented Feb 16, 2011 at 17:56
  • 3
    @Felix Dombek: it's not standard complaint. ISO C++ forbids in-class initialization of non-const static members. You can only do that for integral const static members, and that's because static const integral variables won't be actually put in memory, but will be used as constant at compile time. Commented Feb 16, 2011 at 18:45
  • 2
    @FelixDombek: To answer your question of why the C++ standard doesn't allow this, see the answer here: stackoverflow.com/questions/9656941/… Commented Nov 8, 2012 at 20:30