Ö
Öö Tiib
And the reason is...?
Enumerator may cause inconvenience in C++ when such constant value
should be of particular integral type.
And the reason is...?
Paavo said:(e-mail address removed) wrote in
Yes, this is a declaration which will need a definition in some source
file somewhere. If there is no such definition, the linker may complain
or not, depending on the usage of this symbol and optimization levels,
and obviously depending on which compiler you use.
Unfortunately, at least some MSVC versions fail to compile the correct
code with the definition added, complaining about multiply defined
symbols. So to avoid all the hassle I would suggest just to use:
class C {
private:
enum constants {
m_static = 2
};
Paavo said:MSVC++ 2010 and probably all earlier versions, have not tried with later
ones.
What kludge? To my mind, a const static integral member is a huge kludge.
It is like a Cheshire/Bohr half-existing cat, at one moment it is a real
object occupying a real memory region, on the next it is not. It appears
C++11 has made the situation worse with the ODR-use thing, making it
virtually impossible to predict if such a thing should be defined in a
compilation unit in addition to a declaration or not.
I guess that's why C++11 introduced strongly-typed enums.
Paavo said:And this is ruined by passing it to an innocent-looking std::max() or
adding to an iterator.
enum constants: size_t { kMaxSize = size_t(-1) };
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.