Top "Const-cast" questions

Anything related to the `const_cast` operation in C++, i.e. a form of compile-time conversion where the `const` or `volatile` qualifiers are cast away (removed) from a variable.

How to use const_cast?

I have a private variable in my Student class defined as: const int studentNumnber; I am trying to write a …

c++ const-cast
Is const_cast safe?

I can't find much information on const_cast. The only info I could find (on Stack Overflow) is: The const_…

c++ casting const-cast
Convert const char* to QString

I have to use the output of a function of a type const char* and I need to convert it …

c++ qt qstring qtcore const-cast
How to call a non-const function within a const function (C++)

I have a legacy function that looks like this: int Random() const { return var_ ? 4 : 0; } and I need to call a …

c++ function constants const-correctness 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++ …

c++ const-cast
Remove const-ness from a variable

i'm trying to remove const-ness from a variable (char*), but for some reason when i try to change the value, …

c++ casting constants const-cast
C++: Why is const_cast evil?

I keep hearing this statement, while I can't really find the reason why const_cast is evil. In the following …

c++ pointers casting constants const-cast
C++ difference between adding const-ness with static_cast and const_cast of "this" object?

As per Scott Meyers, to prevent repetition of code in the const version of a getter and the non-const version …

c++ static-cast const-cast
Is it safe to remove const via const_cast and invoke a non-const function that does not modify the resulting object?

I know that casting away const-ness should be done with care, and any attempt to remove const-ness from an initially …

c++ const-cast
What value does const void * offer over void *?

In C++, is there any value in using a const void * for an argument type to a function over a …

c++ constants void-pointers reinterpret-cast const-cast