My Game.cpp function init throws run time error while adding objects to a list. I have the console print message before and after the place of error for debugging. main.cpp creates Game object and calls function init() which creates objects and a list. The function should add them to the list. There are no compile errors and I had this working on what seems identical project. We should expect the message "Items Start Adding" to print before the adding to list and "Items Added" to print afterwards. This would let us know they have been added. I have added the error image below that I get and it seems to open up the list class and point to a exact line of issue in the list class
Thanks
main.cpp
//Included libraries
#include "GameObject.h"
#include "Enemy.h"
#include "Player.h"
#include "Game.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
Game game;
game.init();
}
Game.h
#ifndef GAME_H
#define GAME_H
#include "GameObject.h"
#include "Player.h"
#include "Enemy.h"
#include <list>
#include <time.h>
#include <array>
#include <string>
#include <iostream>
using namespace std;
class Game
{
public:
Game();
~Game();
void init();
private:
//Game Objects
GameObject* player1 = new Player();
GameObject* enemy1 = new Enemy();
GameObject* enemy2 = new Enemy();
GameObject* enemy3 = new Enemy();
GameObject* enemy4 = new Enemy();
//List and iterator
list <GameObject*> listOfObjects;
};
#endif
Game.cpp
#include "Game.h"
Game::Game(){}
Game::~Game(){}
void Game::init()
{
cout << "Items Start Adding" << endl;//Does print
//Add objects to list ERROR ERROR HERE
listOfObjects.push_back(player1);
listOfObjects.push_back(enemy1);
listOfObjects.push_back(enemy2);
listOfObjects.push_back(enemy3);
listOfObjects.push_back(enemy4);
cout << "Items Added" << endl;//Does not print
//Give each item in list random unique place in map
for (iter = listOfObjects.begin(); iter != listOfObjects.end(); iter++)
{
do
{
x = (rand() % 22)+1;
y = (rand() % 22)+1;
}while (array[y][x] == 1);
(*iter)->spawn(to_string(ID), 160, 1, y, x);
ID = ID + 1;
}
cout << "Init Function Complete" << endl;
Sleep(5000);
}