vendredi 28 août 2020

const_cast: modifying a formerly const value is only undefined if the original variable is const

https://stackoverflow.com/a/332086/462608

modifying a formerly const value is only undefined if the original variable is const

...

if you use it to take the const off a reference to something that wasn't declared with const, it is safe.

...

This can be useful when overloading member functions based on const, for instance. It can also be used to add const to an object, such as to call a member function overload.

I am unable to understand the meanings of the above quotes. I request you to give me examples to practically show what these quotes mean.

Aucun commentaire:

Enregistrer un commentaire