In B::foo()
you are calling A::foo()
, passing it this
pointer which points to object of type B
.
Inside A::foo()
you're calling this->g()
which is polymorphic and it will call B::g()
, because type of this
pointer inside A::foo()
is B
.