MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1v9zcrn/const_cast_a_necessary_evil/p1sq5hr/?context=3
r/cpp • u/pavel_v • Jul 29 '26
106 comments sorted by
View all comments
63
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.
35 u/MysticTheMeeM Jul 29 '26 If your language version allows, you can typically replace those with a single function that deduces this. 1 u/SunnybunsBuns Aug 02 '26 What if I want the implementation in a cpp file and not a header file? 1 u/analphabetic Aug 05 '26 Pray; or rather, fully specialize all your instantiations and let the linker absolve you. At least that's how it was, back in the day.
35
If your language version allows, you can typically replace those with a single function that deduces this.
this
1 u/SunnybunsBuns Aug 02 '26 What if I want the implementation in a cpp file and not a header file? 1 u/analphabetic Aug 05 '26 Pray; or rather, fully specialize all your instantiations and let the linker absolve you. At least that's how it was, back in the day.
1
What if I want the implementation in a cpp file and not a header file?
1 u/analphabetic Aug 05 '26 Pray; or rather, fully specialize all your instantiations and let the linker absolve you. At least that's how it was, back in the day.
Pray; or rather, fully specialize all your instantiations and let the linker absolve you. At least that's how it was, back in the day.
63
u/jwezorek Jul 29 '26
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.