/* 4. ´ÙÀ½ ÇÁ·Î±×·¥ÀÇ Ãâ·ÂÀ» ½á¶ó. */ #include int number[5] = { 1, 2, 3, 4, 5 }; // ¿©±â¸¦ ¹Ù²Ü °Í class X { int x; public: X(int a) { x = a; } void foo() { printf("%d\n",x); } virtual void hoo() { printf("%d\n",x); } }; class Y : public X { int y; public: Y(int a,int b) : X(a) { y = b; } void foo() { printf("%d\n",y); } virtual void hoo() { printf("%d\n",y); } }; class Z : public X { int z; public: Z(int a,int b) : X(a) { z = b; } void foo() { printf("%d\n",z); } virtual void hoo() { printf("%d\n",z); } }; void main() { X *p = new X(number[0]); X *q = new Y(number[1],number[2]); X *r = new Z(number[3],number[4]); p->foo(); q->foo(); r->foo(); p->hoo(); q->hoo(); r->hoo(); }