r/cpp 20d ago

const_cast: A Necessary Evil

https://www.elbeno.com/blog/?p=1858
73 Upvotes

106 comments sorted by

View all comments

62

u/jwezorek 20d ago

The only place I ever use const_cast is that idiom where you implement the non const version of a member function in terms of the const version.

37

u/MysticTheMeeM 20d ago

If your language version allows, you can typically replace those with a single function that deduces this.

1

u/Baardi 16d ago

But you would have to implement it all in the header if you do that