Reputation: 91
I'm new to c++ currently working on my assignment and encounter this runtime error "Access violation reading location" when trying to assign iterator pointer into array using for loop.
Flist = data.getFList();
for(Fit = Flist.begin(); Fit != Flist.end(); Fit++)
{
++counter;
cout << "(" << counter << ") Destination: " << Fit->getDest() << " [Class: " ><< Fit->getClass() << "]" << endl;
_getch();
fArr[counter] = *Fit;
}
Staff::Staff()
{
counter = 0;
fArr = new Flight[counter];
};
Flight *fArr;
int counter;
Any help will be great~
Upvotes: 0
Views: 119
Reputation: 12287
When you allocate memory in the constructor, you're creating an array of 0
size, that doesn't really make sense.
Instead, just use a vector of flights: std::vector<Flight> fArr
, and push back to it:
fArr.push_back(*Fit);
Upvotes: 3