#include <iostream>
using namespace std;
struct InvRec
{
int PartID;
float Price;
int Warehouse;
};
typedef InvRec *InvRecptr;
typedef InvRec arr[];
typedef InvRecptr * indexarr;
void deallocate (indexarr & ptrs, int & size)
{
for (int i=0; i<size; i++) delete (ptrs[i]);
delete ptrs;
ptrs = NULL;
size = 0;
};
int getRecordCount();
void main ()
{
char YN;
cout << "press a key, at creation";
cin >> YN;
InvRecptr *InvRecArray = new InvRecptr[10];
for (int i = 0; i < 10; i++)
{
InvRecArray[i]->PartID = i;
cout << "\n i = " << i << "\n";
}
};
the porgram works if the first line in the for loop of main “InvRecArray[i]->PartID = i;
” is commented out but crashes otherwise
The line:
Allocates an array of pointers. The pointers aren’t allocated themselves, though. Therefore, you need a loop like this to allocate the pointers: