samedi 11 septembre 2021

C++ constexpr reference is not const [duplicate]

I have the below simple codes:

constexpr int x = 1;
constexpr int &y = x; -- error. qualifiers dropped in binding reference of type "int &" to intializer of type "const int"

Question:
Why reference y is not a const int &? According to C++ Primer 5th Ed section 2.4.4 (constexpr Variables), all constexpr variable are implicitly const.

Thanks.

Aucun commentaire:

Enregistrer un commentaire