#include <iostream>
using namespace std;
class Top {
protected:
int x;
public:
Top(int n) { x = n; }
virtual ~Top() {}
friend ostream& operator<<(ostream& os, const Top& t) {
return os << t.x;
}
};
class Left : virtual public Top {
protected:
int y;
public:
Left(int m, int n) : Top(m) { y = n; }
};
class Right : virtual public Top {
protected:
int z;
public:
Right(int m, int n) : Top(m) { z = n; }
};
class Bottom : public Left, public Right {
int w;
public:
Bottom(int i, int j, int k, int m): Top(i), Left(0, j), Right(0, k) { w = m; }
friend ostream& operator<<(ostream& os, const Bottom& b) {
return os << b.x << ',' << b.y << ',' << b.z<< ',' << b.w;
}
};
int main() {
Bottom b(1, 2, 3, 4);
cout << sizeof b << endl;
cout << b << endl;
cout << static_cast<void*>(&b) << endl;
Top* p = static_cast<Top*>(&b);
cout << *p << endl;
cout << p << endl;
cout << static_cast<void*>(p) << endl;
cout << dynamic_cast<void*>(p) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIFRvcCB7CnByb3RlY3RlZDoKICAgIGludCB4OwpwdWJsaWM6CiAgICBUb3AoaW50IG4pIHsgeCA9IG47IH0KICAgIHZpcnR1YWwgflRvcCgpIHt9IAogICAgZnJpZW5kIG9zdHJlYW0mIG9wZXJhdG9yPDwob3N0cmVhbSYgb3MsIGNvbnN0IFRvcCYgdCkgewogICAgICAgIHJldHVybiBvcyA8PCB0Lng7CiAgICB9Cn07CmNsYXNzIExlZnQgOiB2aXJ0dWFsIHB1YmxpYyBUb3Agewpwcm90ZWN0ZWQ6CiAgICBpbnQgeTsKcHVibGljOgogICAgTGVmdChpbnQgbSwgaW50IG4pIDogVG9wKG0pIHsgeSA9IG47IH0KfTsKY2xhc3MgUmlnaHQgOiB2aXJ0dWFsIHB1YmxpYyBUb3Agewpwcm90ZWN0ZWQ6CiAgICBpbnQgejsKcHVibGljOgogICAgUmlnaHQoaW50IG0sIGludCBuKSA6IFRvcChtKSB7IHogPSBuO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