Given the following code:
class foo;
foo* instance = NULL;
class foo
{
public:
explicit foo(int j)
: i(j)
{
instance = this;
}
void inc()
{
++i;
}
private:
int i;
};
Is the following use of certain behavior?
const foo f(0);
int main()
{
instance->inc();
}
I ask because I use the class registry, and since I am not modifying directly f, it would be nice to do it const, but then the fregistry is indirectly modified.
EDIT: I mean specific behavior: Is the object placed in any special memory location that can only be written once? Read-only memory is out of the question, at least until constexpr from C ++ 1x. For example, constant primitive types (often) are placed in read-only memory, and execution const_castcan lead to undefined behavior, for example:
int main()
{
const int i = 42;
const_cast<int&>(i) = 0;
}