I encountered an error as the topic says: assignment of data-member ‘RootBoxT<CORE::DoubleWrapper>::innerBox_’ in read-only structure. I “might” know why does this happen, but I need to learn more about the rules.
I made all instances for RootBoxT as const, and the member variable *innerBox_ of class RootBoxT is also const type. In one of the methods of class RootBoxT, I need to update the *innerBox_, so I called delete to free the memory of innerBox_ and assigned it with another const pointer.
My questions is that:
- Is this the right method, that when I need to update the value of a const pointer, I just delete it and assign it with another const pointer?
- Is this error cause by the fact that the instance of
RootBoxTisconstbut one of the methods changed the place that a member variable points to? If not, why does it happen? If so, should I just change these instances to non-const?
I really messed up with const keyword for my current project, as I’m rather new to C++. Thanks.
If you have something like this:
and a
const Sobject (s), the pointers.iisconstbut not theintit points to (*s.i). This means you can write:but not:
because that would modify the pointer value, not what it points to.