Your duplicate()
methods are consistently wrong. Instead of passing an address of an object on stack like you do, allocate the object from the heap using new
and return the pointer to it.
For example ..
shape *duplicate()
{
return new square(length);
}
And once you've done with the duplicated objects, remember to delete
them.
the main area of concern is line 152:
shapelib.push_back(new prism(d,*shapelib[n-1]));
Note that n - 1
must not result in a negative value.