/* * inheritance.cpp * * Created on: 18.04.2013 * Author: trifon */ #include using namespace std; class A { private: int xa; void fa() { cout << "fa()\n"; } protected: int ya; void ga() { cout << "ga()\n"; } public: int za; void ha() { cout << "ha()\n"; } }; class B : public A { private: int xb; void fb() { cout << "fb()\n"; } protected: int yb; void gb() { cout << "gb()\n"; } public: int zb; void hb() { cout << "hb()\n"; } }; class C : public B { private: int xc; void fc() { cout << "fc()\n"; } protected: int yc; void gc() { cout << "gc()\n"; } public: int zc; void hc() { cout << "hc()\n"; xc = yc = yb = ya = 0; gb(); gc(); fc(); ga(); } }; B f(A a) { C c; return c; } int main() { C c; c.zc = c.zb = c.za = 10; c.hc();c.hb();c.ha(); A* pa = &c; // .... A a; // pa = &a; B* pb = (B*)pa; a = f(*pb); cout << pb->zb << endl; return 0; }