std::cout << "Set range: "; std::cin >> range; shape **shapes_list = new shape*[range]; while (i != range) { shapes_list[i] = ShapeFactory::createShape(type); i++; } for (int i = 0; i < range; ++i) { shapes_list[i]->create(); } 

When freeing memory here, destructors of objects are not called.

 for (int i = 0; i < range; ++i) { delete [] shapes_list[i]; } delete [] shapes_list; 

And here it is normally called

 shape* s = ShapeFactory::createShape(1); delete s; 
  • why square brackets in a loop? - vp_arth
  • one
    std :: vector / unuque_ptr not allowed to use? - KoVadim
  • it was necessary to use only an array ... I corrected thanks - Artyom

1 answer 1

 delete [] shapes_list[i]; 

change to

 delete shapes_list[i]; 

With brackets, only needed for shapes_list itself.

  • thanks a lot worked))) - Artyom