3 ms·
I've actually just looked at the standard and there is a clear example something like this: int x; int const *cpx = &x; int *px = const_cast<int *>(cpx);
by ambrop7 13y ago
I've actually just looked at the standard and there is a clear example something like this:
int x;
int const *cpx = &x;
int *px = const_cast<int *>(cpx);
*px = 1; // defined behavior, modifying non-const object through non-const pointer
While this may seem ok here, consider that the same applies to functions taking pointers to const. While this usually means the function won't modify the pointed-to objects, there is no guarantee from the language about that.