I have read that using const_cast to modify an object that was originally
declared const can lead to undefined behavior.
Would this be true in the case of a user defined object containing a const
data member as in the example below, and if so, why?
In what cases can modification of an originally declared const object be
problematic?
I would appreciate any comments.
struct TestClass
{
TestClass() : m_s("123") {}
const string m_s;
};
TestClass b;
const_cast<string&>(b.m_s) = "456"; // works fine but is this acceptable ?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]