#include <iostream>
struct Base
{
virtual void f(){ std::cout << "Base::f()" << std::endl; }
};
struct Derived
: Base
{
virtual void f() override { std::cout << "Derived::f()" << std::endl; }
};
int main()
{
Derived d;
Base &b = d;
d.f(); //calls Derived::f()
b.f(); //calls Derived::f()
d.Base::f(); //calls Base::f()
b.Base::f(); //calls Base::f()
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IEJhc2UKewogICAgdmlydHVhbCB2b2lkIGYoKXsgc3RkOjpjb3V0IDw8ICJCYXNlOjpmKCkiIDw8IHN0ZDo6ZW5kbDsgfQp9OwpzdHJ1Y3QgRGVyaXZlZAo6IEJhc2UKewogICAgdmlydHVhbCB2b2lkIGYoKSBvdmVycmlkZSB7IHN0ZDo6Y291dCA8PCAiRGVyaXZlZDo6ZigpIiA8PCBzdGQ6OmVuZGw7IH0KfTsKCmludCBtYWluKCkKewoJRGVyaXZlZCBkOwoJQmFzZSAmYiA9IGQ7CgkKCWQuZigpOyAvL2NhbGxzIERlcml2ZWQ6OmYoKQoJYi5mKCk7IC8vY2FsbHMgRGVyaXZlZDo6ZigpCglkLkJhc2U6OmYoKTsgLy9jYWxscyBCYXNlOjpmKCkKCWIuQmFzZTo6ZigpOyAvL2NhbGxzIEJhc2U6OmYoKQp9Cg==