Article

const_cast: A Necessary Evil

raymii ·Lobsters ·Published 2026-07-29

Thoughts both confusing and enlightening. Thoughts both confusing and enlightening. We don’t like const_cast much. It’s ugly, and can even lead to undefined behaviour. But unfortunately sometimes it’s needed. Even aside from interacting…

From the article

Thoughts both confusing and enlightening.

Thoughts both confusing and enlightening.

We don’t like const_cast much. It’s ugly, and can even lead to undefined behaviour. But unfortunately sometimes it’s needed. Even aside from interacting with C libraries which don’t respect const , there is at least one place in the C++ standard that requires you to use it.


Share this resource


Discovered 2026-08-03 Source Lobsters Archive 2026-08 →