#include <iostream>
struct Base
{
virtual void test() { std::cout << "Base" << std::endl; }
};
struct Derived : Base
{
virtual void test() { std::cout << "Derived" << std::endl; }
};
void f(Base *base) { base->test(); }
void g(Base &base) { base.test(); }
void h(Base base) { base.test(); }
int main()
{
Derived d;
Derived *dp = &d;
Base *bp = dp;
f(dp); // Derived
f(bp); // Derived
g(d); // Derived
h(d); // Base
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IEJhc2UKewogIHZpcnR1YWwgdm9pZCB0ZXN0KCkgeyBzdGQ6OmNvdXQgPDwgIkJhc2UiIDw8IHN0ZDo6ZW5kbDsgfQp9OwpzdHJ1Y3QgRGVyaXZlZCA6IEJhc2UKewogIHZpcnR1YWwgdm9pZCB0ZXN0KCkgeyBzdGQ6OmNvdXQgPDwgIkRlcml2ZWQiIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKdm9pZCBmKEJhc2UgKmJhc2UpIHsgYmFzZS0+dGVzdCgpOyB9CnZvaWQgZyhCYXNlICZiYXNlKSB7IGJhc2UudGVzdCgpOyAgfQp2b2lkIGgoQmFzZSBiYXNlKSAgeyBiYXNlLnRlc3QoKTsgIH0KCmludCBtYWluKCkKewogIERlcml2ZWQgZDsKICBEZXJpdmVkICpkcCA9ICZkOwogIEJhc2UgICAgKmJwID0gZHA7CiAgCiAgZihkcCk7IC8vIERlcml2ZWQKICBmKGJwKTsgLy8gRGVyaXZlZAogIGcoZCk7ICAvLyBEZXJpdmVkCiAgaChkKTsgIC8vIEJhc2UKCiAgcmV0dXJuIDA7Cn0=