Hi i have been fighting with this for hours now and i can't seem to get it. i am getting the message Access violation reading location 0xccccccc8. when i try to print my dynamic array during the overloaded << function in my Flight class. where the error happens is surrounded by *s
Person * crew = new Person[planeType.getCrewSize()];
This creates a new pointer called "crew" in the scope of Flight::Flight(), which is gone at the end of that function. output.crew remains uninitialized, and since output was created on stack, it is 0xccccccc, the uninitialized stack memory in Windows debug builds.
Best way to go about it is to use vectors and initialize them before the opening brace of the constructor where possible.
I hope they will explain why this is a bad thing to do (if they don't, read up on rule of three and exception safety)
The minimal fix is to not make a new crew in the constructor, but instead overwrite the existing one: crew = new Person[planeType.getCrewSize()];
(it would be better to initialize it in the member initialization list, but to do that you'd have to restructure the class to move planeType before crew)
Wow i am so dumb. haha by changing the Person * crew = new [planeType.getCrewSize()] in the constructor to crew = new [planeType.getCrewSize()] it worked because i was overwriting the one in the class definition its self. Thank you so much!