#include #include #include "shape.h" using namespace std; int main() { Shape* sList[10]; // array of 10 shapes sList[0] = new Circle; // default constructor sList[1] = new Circle(10, 20, 100); sList[2] = new Circle("red", 4, -1, 30); sList[3] = new Rectangle; // default constructor sList[4] = new Rectangle(5, 10, 100, 200); sList[5] = new Rectangle("mauve", -5, -20, 50, 40); sList[6] = new Circle(-5, -10, 41); sList[7] = new Rectangle("white", 1, 2, 6, 7); sList[8] = new Circle; sList[9] = new Rectangle(2, 2, 9, 9); // Note that we are using the property that base class pointer // may be pointed at derived objects. Each pointer is type // Shape*, and each points to a rectangle or a circle // Also note that BECAUSE the calling variable is of type // Shape*, we can only call functions in the Shape class for (int i = 0; i < 10; i++) { cout << "Shape " << i << "'s color is: " << sList[i]->GetColor() << '\n'; } /* // However, note that the following attempt to PRINT each shape // with the Print() function is NOT legal, because Print() is not // declared in class Shape for (int i = 0; i < 10; i++) { cout << "Shape " << i << " "; sList[i]->Print(); cout << '\n'; } */ }