For part of my assignment I need to create a vector of pointers that point to shape objects. I have a few different classes, the base class Shape, and a few derived classes such as Circle and Rectangle. In the main I need to construct the vector and then pass the vector to a function that will expand the dimensions of the shape. So the function will multiply the radius, the length and the width by a certain number. This is my code so far:
vector<Shape*> shapes;
shapes.push_back(circ1);
shapes.push_back(rect1);
with circ1 and rect 1 being objects from the class Circle and Rectangle. I also defined circ1 and rect1 but didnt include the code here.
my function is called expandAll(), this is what i tried to do:
void expandAll(vector<Shape*> shapes, int factor)
{
for (int i = 0; i < shapes.size(); i++)
{
shapes[i] = shapes[i] * factor;
}
}
This is wrong due to the error that popped up. To sum up, I need help creating a vector of pointers and using that vector in a function. Thanks in advance.