You have two different versions of printMessage
, one which is const
and one which isn't. The two are unrelated, even though they have the same name. The new function in Cow
hides the one in Animal
, so when you call it directly the compiler only considers the Cow
version.