A co-worker asked about some code like this that originally had templates in it.
I have removed the templates, but the core question remains: why does this compile O
The instance object of class X is not const. It is merely referenced by an object which is const. Const-ness recursively applies to subobjects, not to referenced objects.
By the alternative logic, a const method wouldn't be able to modify anything. That is called a "pure function," a concept which doesn't exist in current standard C++.