Instantiation:
weapons.push_back(new Pistol());
weapons.push_back(new Rifle());
weapons.push_back(new Shotgun());
destructor, when the first delete happens, the code breaks. This happens when I close the program.
Brain::~Brain()
{
for (unsigned int i = 0; i < weapons.size(); i++)
{
delete weapons[i]; // this is where the code breaks
}
}
I get a warning:
Unhandled exception at 0x0096371f in D3D10DEMO.exe: 0xC0000005: Access violation reading location 0x000002ce.
weapons is this:
weapons(vector<Gun*>())
Edit - I have deleted much of the code from this question but I have also cut down my program so as to reproduce the problem in a much smaller solution here: