Your problem seems to be reasoning about pointers, rather than anything specific to operators.
I have the const pointer to a Circle. So, my pointer cannot change address
true - whatever object your const pointer is initialized to point to, it can never change to point at some other object instead.
however the Circle value itself inside the address can change
Yes,if your const pointer points to an object, you can mutate the object in-place
So my attempt is to change the Circle value inside innerCircle
But this assumes innerCircle
points to an object. You initialized it to nullptr
, which means it does not point to any object. That's what nullptr
(or the old NULL
) means.
Since your pointer doesn't point at an object, there's nothing there you can legally mutate. Since you declared your pointer const
, you also can't ever change it to point at a real object.
After that, as borgleader says, you get the recursive definition of circle problem.
Maybe Circle
should just have a (maybe-nullptr) pointer to circle, which it can mutate to point at a Circle
if requested? Eg.
struct Circle
{
Circle() : innerCircle(nullptr) {}
Circle* innerCircle;
void insert(Circle *inner)
{
innerCircle = inner;
}
bool hasInner() const { return (innerCircle != nullptr); }
Circle* getInner() const) { return innerCircle; }
};