1       #include <iostream.h>
2       class Shape {
3          public:
4               int x, y;
5               virtual void Print() {
6                       cout << "Shape x,y " << x << " " << y << endl;
7               }
8       };
9       class Rect: public Shape {
10         public:
11              int width, heigth;
12              virtual void Print() {
13                      cout << "Width Heigth" << width << " " << heigth << endl;
14              }
15      };
16      class Circle : public Shape{
17         public:
18              int radius;
19              virtual void Print() {
20                      cout << "Radius" << radius << endl;
21              }
22      };
23      class Combo : public Shape{
24         public:
25              Circle c;
26              Rect r;
27              virtual void Print() {
28                      r.Print(); c.Print();
29              }
30      };
31
32      main() {
33              Shape s; Rect r; Circle c; Combo com;
34              r.Print();
35              s = r;
36              s.Print();
37              c.Print();
38      }
39                        << "Radius" << radius << endl;
21              }
22      };
 

(gdb) p c
$1 = {<Shape> = {x = 1073764735, y = -1073742648,
    _vptr. = 0x8049ac4 <Circle virtual table>}, radius = 1074292715}
(gdb) p com
$2 = {<Shape> = {x = 134514260, y = 7,
    _vptr. = 0x8049ab8 <Combo virtual table>}, c = {<Shape> = {x = 134520220,
      y = 134513960, _vptr. = 0x8049ac4 <Circle virtual table>},
    radius = 1073773012}, r = {<Shape> = {x = 1073813124, y = 134513488,
      _vptr. = 0x8049ad0 <Rect virtual table>}, width = 1073785336,
    heigth = -1073742684}}
(gdb)
 

main() {
        Shape s, *s1; Rect r, *r1; Circle c; Combo com;
        r.Print();
        s1 = &r;
        s1->Print();
        c.Print();
}