Let's say we have these classes:
class A {
virtual void foo() {} //implemented
virtual void bar() = 0;
};
class B: public A {
virtual void foo() override {} //implemented
virtual void bar() override {} //implemented
};
class C: public A {
virtual void foo() override {} //implemented
virtual void bar() override {} //implemented
};
Then let's say we do this:
shared_ptr<A> spa;
if (someCondition) {
spa = make_shared<B>();
} else {
spa = make_shared<C>();
}
spa->foo();
spa->bar();
What happens in the background? Obviously, pure virtual function bar() MUST be implemented in the derived classes - so is there an implicit cast that happens for the shared ptr to use the derived class implementation? In the case of bar, we are still overriding despite implementation in the base class, so will it also do a an implicit cast of some sort to use the derived class implementation?
Essentially, it's not a question of what will happen, but moreso a question of how what is happening is happening.