#include<iostream>
using namespace std;
class A
{
public:
virtual void f1() { cout << "A::F1\n"; }
void f2() { cout << "A::F2\n"; }
void f3() { cout << "A::F3\n"; }
};
class B :public A
{
public:
void f1() { cout << "B::F1\n"; }
virtual void f2() { cout << "B::F2\n"; }
void f3() { cout << "B::F3\n"; }
};
class C :public B
{
public:
void f1() { cout << "C::F1\n"; }
void f2() { cout << "C::F2\n"; }
virtual void f3() { cout << "C::F3\n"; }
};
class D :public C
{
public:
void f1() { cout << "D::F1\n"; }
void f2() { cout << "D::F2\n"; }
void f3() { cout << "D::F3\n"; }
};
int main()
{
B* d1 = new D();
d1->f1();
d1->f2();
d1->f3();
cout << "\n";
A* d2 = new D();
d2->f1();
d2->f2();
d2->f3();
cout << "\n";
C* d3 = new D();
d3->f1();
d3->f2();
d3->f3();
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNsYXNzIEEKewpwdWJsaWM6Cgl2aXJ0dWFsIHZvaWQgZjEoKSB7IGNvdXQgPDwgIkE6OkYxXG4iOyB9Cgl2b2lkIGYyKCkgeyBjb3V0IDw8ICJBOjpGMlxuIjsgfQoJdm9pZCBmMygpIHsgY291dCA8PCAiQTo6RjNcbiI7IH0KIAoKfTsKIApjbGFzcyBCIDpwdWJsaWMgQQp7CnB1YmxpYzoKCSB2b2lkIGYxKCkgeyBjb3V0IDw8ICJCOjpGMVxuIjsgfQoJIHZpcnR1YWwgdm9pZCBmMigpIHsgY291dCA8PCAiQjo6RjJcbiI7IH0KCSB2b2lkIGYzKCkgeyBjb3V0IDw8ICJCOjpGM1xuIjsgfQp9OwpjbGFzcyBDIDpwdWJsaWMgQgp7CnB1YmxpYzoKCXZvaWQgZjEoKSB7IGNvdXQgPDwgIkM6OkYxXG4iOyB9Cgl2b2lkIGYyKCkgeyBjb3V0IDw8ICJDOjpGMlxuIjsgfQoJdmlydHVhbCB2b2lkIGYzKCkgeyBjb3V0IDw8ICJDOjpGM1xuIjsgfQ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