I hope I'm phrasing my self well, let me explain.
My hirarchey :
Shape
Circle Quad
Square
And another class , allShapes
, which contains a dynamic array of pointers to Shapes. (Shape **) and its size.
I'm trying to implement +
operator, which suppose to create a new allShapes
object, by creating a new Shape **
array from the elements stored inside the two objects that initiated the operator. Here is the function:
allShapes allShapes::operator+(const allShapes & other) const
{
allShapes newAllShapes;
newAllShapes._arr = new Shape *[_size + other._size];
newAllShapes._size = _size + other._size;
int i;
for (i = 0; i < _size; i++)
newAllShapes._arr[i] = _arr[i];
for (int j = 0; j < other._size; j++, i++)
newAllShapes._arr[i] = other._arr[j];
return newAllShapes;
}
I initially tryed this but this result in an error in my destructor, because I'm only copying the addresses I guess it tries to delete the same object twice..
I tryed using the Shape CConstructor , by replacing the lines with this:
newAllShapes._arr[i] = new Shape(*_arr[i]);
My CConstructor:
Shape::Shape(const Shape & other)
{
_totalNumOfShapes++;
_shapeName = other._shapeName;
_centerPoint = other._centerPoint;
}
But it result in an error
"Object of abstract class are not allowed" .
How can I solve this? Hope I included everything needed.