I'm creating an ADT Bag and have to dynamically allocate size for arrays. Once the array becomes full I need to dynamically allocate more space for it, so it can never be full. However when my original array is full, I'm unable to add another item to it, as I get the Segmentation Fault (core dumped) error. Any insight onto why this is happening would be greatly appreciated.
Header File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
template <typename ItemType>
13 class itemBag : public BagInterface<ItemType> {
14 private:
15 /** Maximum capacity of this bag. */
16 int arraySize = 6;
17
18 ItemType* items;
19 ItemType* receipts;
20 /** Data storage. */
21 // items = new ItemType[arraySize];
22 // receipt = new ItemType[arraySize];
23
24 /** Number of items in this bag. */
25 int itemCount = 0;
26
27 /** Maximum capacity of this bag. */
28 int maxItems = arraySize;