Are compilers smart enough to optimize the call to Foo() when derived class does not override it?
struct Base {
virtual void Foo(int x) {}
};
struct DerivedA : Base {};
struct DerivedB : Base {
void Foo(int x) override { Bar(x); }
};
void Call(Base* b) {
b->Foo(42); // Is this optimized out for DerivedA?
}
int main() {
Base* a = new DerivedA();
Base* b = new DerivedB();
Call(a);
Call(b);
return 0;
}