Suppose there's an abstract base class and two inheriting
classes declared as follows.
class Shape {double sizeA;};
class Ellipse : Shape {double sizeB};
class Rect : Shape {double sizeC};
In our program we will have a pointer to a shape but we
don't know which one yet. So, we declare it as follows.
Shape *shapy;
Then, i'd like to do this:
shapy = new Ellipse ();
shapy->sizeA = 4;
shapy->sizeB = 5;
or this:
shapy = new Rect ();
shapy->sizeA = 4;
shapy->sizeC = 5;
but, while the first two lines work fine (i.e. the computer
finds the sizeA and can handle the pointers to Ellipse
and Rect), the implementation specific variables are not
reachable. How can i solve this without binding shapy to
Ellipse or Rect explicitly?
--
Vänligen Kerstin Viltersten
(The Cool Giraffe)