What is the difference between these member variables:
struct my_class {
static const int i = 0;
static constexpr int j = 0;
};
If my understanding is correct, I'm able to use both i
and j
as compile time constants. That is, both std::array<int, my_class::i>
and std::array<int,my_class::j>
should work.
There is no difference for members of integral or enumeration type (as in your example). For all other types, constant expressions require constexpr
:
an lvalue-to-rvalue conversion (4.1) unless it is applied to
- a non-volatile glvalue of integral or enumeration type that refers to a complete non-volatile const object with a preceding initialization, initialized with a constant expression, or […]
- a non-volatile glvalue that refers to a non-volatile object defined with
constexpr
, or that refers to a non-mutable sub-object of such an object, or […]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With