3 ms·
It's a weird name for "readonly", not "immutable", as evidenced by this example: int x = 0; int const *px = &x; ++x; // *px changed There's no way to
by int_19h 4y ago
It's a weird name for "readonly", not "immutable", as evidenced by this example:
int x = 0;
int const *px = &x;
++x; // *px changed
There's no way to indicate true immutability in C++, unfortunately. The language does decree that any object (which in C++ parlance includes ints etc) with a const type cannot be mutated without triggering UB; but there's no way to declare a pointer or reference that can only point to such objects.