Is this a valid use of a const_cast ? I am using it in a constructor and it looks as follows:
KeyLiteObject(const char * extension, const char * swap_suffix)
: _extension(extension),
_swap_suffix(swap_suffix),
_swap_suffix_extension(swap_suffix)
{
const_cast<std::string*>(&_swap_suffix_extension)->append(_extension);
}
Yes, the strings will never change.
Assuming that _swap_suffix_extension is a const std::string then why not just do this:
Then you can totally avoid the const_cast …