I\'m working on a kernel and I want to make my static data member constexpr
so I can have its values in an enum class
. However, if I do so I get an
A static data member shall be defined outside the class if it is odr-used---period. There are no exceptions to this rule.
In the case that the data member is constexpr
, it must also be initialized inside the class definition. However this does not abrogate the requirement to define it outside the class.
Correct code:
class Terminal
{
constexpr static uint32_t col_map[16] = { /* ... */ };
// ...
};
constexpr uint32_t Terminal::col_map[16]; // definition
It's counterintuitive, but that's just the way it is.