#include "container.h"
Container::Container()
{
//_items=NULL; Don't know how to set the 100 elements of the the array equal to 0, what I really mean is that I want that memory space to free of junk...
_count=0;
}
Container::~Container()
{
if (_items != (NULL))
{
delete [] _items;
}
}
void Container::add_item(Item item)
{
_items[_count]= item;
_count++;
}
void Container::displayitems()
{
for (int i=0; i < 100; i++)
{
if (_items[_count].getId());
}
}
void Container::removeitems(int pos)
{
for (int i=pos; i < _count-1; i++)
{
_items[i] = _items[i+1];
}
}
/*void Container::numberofitems()
{
int a;
a= _items.size(); // Don't know how to get the size of the private array
}*/
In "Container::~Container( )" you're deallocating memory that was never allocated. Remove the "delete []" from the destructor. Also, "Container::_items" will never be null since it's an array of "Item"s, not pointers.