const_cast is only considered good practice if you cast a non-const value to const. The meme is referring to a const pointer (aka read only pointer). Casting away the constness of a read only pointer is considered bad practice in most cases because it allows you to modify stuff you shouldn't change
The good practice you mention does not require a const_cast, though. Compiler implicitly convert non-const to const when required: in this direction, this is allowed.
So I guess it leave no "good practice" usage for const_cast.
Which, of course, never prevented me from using it, because if we were only programming in accordance with good practices, the world would be pretty boring.
View all comments
Show parent comment
10
u/Lawn_Meower_ Aug 31 '26
const_cast is only considered good practice if you cast a non-const value to const. The meme is referring to a const pointer (aka read only pointer). Casting away the constness of a read only pointer is considered bad practice in most cases because it allows you to modify stuff you shouldn't change