constexpr/const dilemma

Below is some code the exemplifies the user of constexpr. Why could I not use "const" instead?

1
2
3
4
5
6
7
8
9
constexpr int max = 100;
void use(int n)
{
constexpr int c1 = max+7; // OK: c1 is 107
const int c2 = n+7; // OK, but don’t try to change the value of c2
// ...
c2 = 7; // error: c2 is a const
}
Such
Topic archived. No new replies allowed.