Question: I am having an issue with the following code for C + + . b#include Rectangle.h #include Circle.h #include void showShape ( Shape
I am having an issue with the following code for C
b#include "Rectangle.h
#include "Circle.h
#include
void showShapeShape shape
shapedraw;
Why can you use a pointer and not a Shape object?
I could not get this to work with a showShapeuniquePtr shape function.
void showShapeuniqueptr shape
shapedraw;
int main
vector shapes;
Rectangle rectangle;
shapes.pushback&rectangle;
Circle circle;
shapes.pushback&circle;
for int i ; i shapes.size; i
showShapeshapesati;
cout shapes.ati endl;
cout endl;
vector uniqueShapes ;
uniqueptr rectanglePtr;
rectanglePtr makeunique ;
rectanglePtrdraw;
uniqueptr circlePtr;
circlePtr makeunique ;
circlePtrdraw;
uniqueShapes.at moverectanglePtr;
uniqueShapes.at movecirclePtr;
uniqueShapespushbackmoverectanglePtr;
uniqueShapespushbackmovecirclePtr;
Press control k c to comment out large sections of code.
Press control k u to undo the commented out code.
uniqueShapes.at makeunique ;
uniqueShapes.at makeunique ;
uniqueShapespushbackmakeunique ;
uniqueShapespushbackmakeunique ;
for int i ; i uniqueShapes.size; i
showShapeuniqueShapesati;
This line above says that is has been deleted somewhere already. I do not know why.
uniqueShapes.atidraw;
for auto index : shapes
delete index;
The TA said it is supposed to work the same, but did not help me solve the issue. I only have the one instance of the delete right above None of my header or cpp files use delete. Why is showShapeuniqueShapesati; not working?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
