I have 2 questions regarding the program below: 1. Does the program only create elements (type rectangle and hexagon) as dynamic, or are the pointers to them dynamic?
2. Why the program has no deletion at the end. for example, something like this: (if I correctly assume that only elements are dynamic ..)
for(i=0;i<3;i++) delete shapeArray[i];
Thank you very much, this site helps me a lot with things that my teachers cannot help! Sheeran
program:
int main() { // Create array of pointers to Shapes of various types. const int NUM_SHAPES = 3; Shape * shapeArray[] = { new Hexagon(), new Rectangle(), new Hexagon() }; // Set positions of all the shapes. int posX = 5, posY = 15; for (int k = 0; k < NUM_SHAPES; k++) { shapeArray[k]->setPosition(posX, posY); posX += 10; posY += 10; }; // Draw all the shapes at their positions. for (int j = 0; j < NUM_SHAPES; j++) { shapeArray[j]->draw(); } return 0; }
source share