Aaron Tee
Aaron Tee

Reputation: 91

Access violation reading location 0xcccccd84

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;
}

Constructor

Staff::Staff()
{
    counter = 0;
    fArr = new Flight[counter];
};

Header

Flight *fArr;
int counter;

Any help will be great~

Upvotes: 0

Views: 119

Answers (1)

Collin
Collin

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

Related Questions