Search code examples
c++const-cast

Correct usage(s) of const_cast<>


As a common rule, it is very often considered a bad practice to use const_cast<>() in C++ code as it reveals (most of the time) a flaw in the design.

While I totally agree with this, I however wonder what are the cases were using const_cast<>() is ok and the only solution.

Could you guys please give me some examples you know/you encountered ?

Thank you very much.


Solution

  • const_cast is also used to remove volatile modifiers, as put into practice in this (controversed) article:

    http://www.drdobbs.com/184403766