In cppref it gives the syntax of constant initialization:
static T & ref = constexpr;
static T object = constexpr;
Here's my two questions:
How could a lvalue reference T & without const be bound to a constexptr,which is constant and unmodifiable ?
I try to provide some example but failed:
static int& ref = 6; //error, need a `const`
constexpr int a = 6; static int& ref = a; //error, need a `const`
Is it a necessity for the object of constant initialization to be const/static ?In the standard it says:
Constant initialization is performed if a variable or temporary object with static or thread storage duration is initialized by a constant initializer for the entity.
Here the standard does not specify the obj to be const-qualified/static-qualified.
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