Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,835 of 33,346    |
|    Jonathan Thornburg to All    |
|    Re: boost::format vs. in-class 'static c    |
|    23 Jan 12 17:42:41    |
      From: clcppm-poster@this.is.invalid              I wrote:       | I recently ran across an interesting problem in combining two parts of       | C++ that individually work beautifully: boost::format and in-class       | 'static const int' constants.       [[example omitted]]       | So, what to do if we want to use boost::format to print out (messages       | which include) in-class constant ints? I can see several possible       | solutions:       |       | We could explicitly define the in-class constant ints outside the class       | declaration. This is awkward on two grounds:       | * it makes the code less readable: N must then be initialized in the       | definition,              Daniel Kr?gler replied       > This is wrong, providing the definition separately does not require to       > move the initializer to the point of the definition. According to       > [class.static.data] p3:       >       > "[..] The member shall still be defined in a namespace scope if it is       > odr-used (3.2) in the program and the namespace scope definition shall       > not contain an initializer."              My mistake -- thanks for correcting me! That removes the major objection       I had to this approach.                     [[...]]       | * if the class is actually a template, the definition needs to be       | replicated for each instantiation of the template              > I don't know what you mean with "replicated", and I don't see a problem       > here for you. It is the compiler who has to ignore the multiple       > instantiations, not you.              I was thinking of the following slightly-more-elaboprate example,       where the in-class const int lives in a template class:               #include |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca