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
You are calling foo on object, not on this.
foo
object
this
Since object is declared as an X&, in a constant CX, it is actually an X& const (which is not the same as const X&) allowing you to call non const methods on it.
X&
X& const
const X&