I have a base class Shape
that has derived classes like Ellipse
and Rectangle
.
In one function, I have a variable:
Shape activeShape(black, black, {0,0}, {0,0}, false);
and later in that function:
activeShape = updateShape(isButton, activeShape, true);
updateShape
looks like this:
Shape updateShape(int button, Shape active, bool leftClick)
{
switch(button)
{
case 1:
return active;
case 2:
return Line(active.getFillColor(), active.getBorderColor(), active.getP1(), active.getP2(),false);
break;
case 3:
return Rectangle(active.getFillColor(), active.getBorderColor(), active.getP1(), active.getP2(),false);
break;
case 4:
return FilledRectangle(active.getFillColor(), active.getBorderColor(), active.getP1(), active.getP2(),false);
break;
case 5:
return Ellipse(active.getFillColor(), active.getBorderColor(), active.getP1(), active.getP2(),false);
break;
case 6:
return FilledEllipse(active.getFillColor(), active.getBorderColor(), active.getP1(), active.getP2(),false);
break;
default:
if(leftClick)
{
active.setColor(getEnumColor(button), active.getBorderColor());
}
else
active.setColor(active.getFillColor(), getEnumColor(button));
break;
};
return active;
}
So as I'm returning things like Rectangle
, they are being casted as a Shape
. Which is exactly not what I want.
What do I need to do to get activeShape
to become one of Shape
s derived classes?