I have this piece of code (contrived from my real-life trouble)
It cannot compile, complaining ExtendsB does not implement B::Run(A* a)
. However, it has no
The error is pretty clear: You need void Run(A*)
in your class ExtendedB
, but you don't have that. All you have is void Run(ExtendedA*)
, but that's not the same: The base class promises to accept any A
-pointer, but your ExtendedB::Run
is pickier and only accepts a narrow subset.
(You're confusing covariance and contravariance, but that is not relevant for C++, since C++ does not allow contravariant overrides.)