Dynamic array of pointers vs dynamic array of objects
Hello Smart people!
Can someone explain to me the difference between dynamic array of pointers vs dynamic array of objects by giving a real life example. Following is the code that I am using for dynamic array of objects. I am skipping initialization and other member functions.
class Inventory {
Item *itemList;
int idx, count, size;
public:
void appendItem (char ttl[]);
void resizeArray();
};
void Inventory::appendItem (char ttl[])
{ if (count == size)
{resizeArray(); }
itemList[count].set(ttl)
}
void Inventory::resizeArray()
{Item *itm = new Item[size ++];
if (itm == 0) {cout << "Out of memory\n"; exit(1); }
for (int i = 0; i < count; i++)
{itm[i] = itemList[i]; }
delete [] itemList;
itemList = itm;
}
how this code will change to allocate an array of item pointers of type Item*?????