#include <iostream>
using namespace std;
class A
{
public:
int x;
int y;
virtual int add() = 0;
};
class B
{
public:
int a;
int b;
virtual int sub() = 0;
};
class C : public A, public B
{
public:
C() { x = 1; y = 2; z = 3; a = 4; b = 5; c = 6; }
int c;
int z;
virtual int add() { cout << "add: " << a << " + " << z << endl; return a + z; }
virtual int sub();
int mul() { return b * y; };
B* getBptr() { return (B *)this; }
};
int C::sub()
{
cout << "sub: " << c << " - " << x << endl;
return c - x;
}
int main()
{
A *p = new C;
cout << p->add() << endl;
cout << ((B *)p)->sub() << endl;
cout << ((C *)p)->mul() << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQQp7CnB1YmxpYzoKICAgIGludCB4OwogICAgaW50IHk7CiAgICB2aXJ0dWFsIGludCBhZGQoKSA9IDA7Cn07CgpjbGFzcyBCCnsKcHVibGljOgogICAgaW50IGE7CiAgICBpbnQgYjsKICAgIHZpcnR1YWwgaW50IHN1YigpID0gMDsKfTsKCmNsYXNzIEMgOiBwdWJsaWMgQSwgcHVibGljIEIKewpwdWJsaWM6CiAgICBDKCkgeyB4ID0gMTsgeSA9IDI7IHogPSAzOyBhID0gNDsgYiA9IDU7IGMgPSA2OyB9CiAgICBpbnQgYzsKICAgIGludCB6OwogICAgdmlydHVhbCBpbnQgYWRkKCkgeyBjb3V0IDw8ICJhZGQ6ICIgPDwgYSA8PCAiICsgIiA8PCB6IDw8IGVuZGw7IHJldHVybiBhICsgejsgfQogICAgdmlydHVhbCBpbnQgc3ViKCk7CiAgICBpbnQgbXVsKCkgeyByZXR1cm4gYiAqIHk7IH07CgogICAgQiogZ2V0QnB0cigpIHsgcmV0dXJuIChCICopdGhpczsgfQp9OwoKaW50IEM6OnN1YigpCnsKICAgIGNvdXQgPDwgInN1YjogIiA8PCBjIDw8ICIgLSAiIDw8IHggPDwgZW5kbDsKICAgICByZXR1cm4gYyAtIHg7Cn0KCmludCBtYWluKCkKewogICAgQSAqcCA9IG5ldyBDOwogICAgY291dCA8PCBwLT5hZGQoKSA8PCBlbmRsOwogICAgY291dCA8PCAoKEIgKilwKS0+c3ViKCkgPDwgZW5kbDsKICAgIGNvdXQgPDwgKChDICopcCktPm11bCgpIDw8IGVuZGw7Cn0K