Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion about constant initialization

Tags:

In cppref it gives the syntax of constant initialization:

static T & ref = constexpr; 
static T object = constexpr;    

Here's my two questions:

Q1

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`  

Q2

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.