Question: please help in fixing memory leaks in below classes shelf.cpp #include Shelf.h Shelf::Shelf(string n, int s) { name = n; capacity = s; foodRow =
please help in fixing memory leaks in below classes shelf.cpp
#include "Shelf.h"
Shelf::Shelf(string n, int s) { name = n; capacity = s; foodRow = new const Food*[s]; size = 0; } void Shelf::AddFood(const Food *f) { if(size < capacity) { foodRow[size++] = f; } } void Shelf::ShowInventory() const { cout << "Food in " << name << endl; for( int i=0; i
const char* Shelf::GetName() { return name.c_str(); }
Cabinet.cpp
#include "Cabinet.h"
Cabinet::Cabinet(string n, int s) { name = n; capacity = s; shelvesRow = new Shelf*[s]; size = 0; } void Cabinet::AddShelf(Shelf *f) { if(size < capacity) { shelvesRow[size++] = f; } } void Cabinet::ShowInventory() { //cout << "+++++++++++++++++++++++++++++++++" << endl; cout << "Inventory of " << name << endl;
for(int i=0; i
//cout << "+++++++++++++++++++++++++++++++++" << endl; }
double Cabinet::GetAveragePrice() { double totalPrice = 0; int count = 0; for(int i=0; i
return totalPrice/count; }
am getting below leaks
LEAKER: errors found! Leaks found: 3 allocations (72 bytes). unknown:unknown():0 memory leak: memory was not deallocated. unknown:unknown():0 memory leak: memory was not deallocated. unknown:unknown():0 memory leak: memory was not deallocated.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
