You're already using
const
. If your code bypasses that (e.g. by casting way the
const
, accessing the passed argument by some other means (e.g. via a pointer to the object that is passed by some other means)) then all bets are off. Casting away
const
and then modifying the object gives undefined behaviour, and there is no way to prevent that other than directing the programmer "don't do that". If programmers are determined enough to change the object, you can't prevent that. —
Peter 26 secs ago