Liste des Groupes | Revenir à cl c |
Em 10/12/2024 10:53 AM, Bart escreveu:So it looks like const/constexpr do different things, for example:>It means the initialization expression must be evaluated at compilation.
It depends on what constexpr means.
Also the declarator can be used in another expression as constant.
Sample
constexpr int a = 1;
constexpr int b = a+1;
But the expression is always something the compiler need to check if is constant or not.
So, what I suggest is if the init expression is a constant expression (something we know at compile time) then the declarator is real constexpr (no need for a new keyword)
For instance:
const int a = 1;
const int b = a+1;
Even if not constant, the compiler can do at compile time.
for instance.
int a = 1+2;
So this has to be done anyway.
The only difference is that using 'a' cannot be used as constant in another expression.
Les messages affichés proviennent d'usenet.