C
canned.net
I have a class Scene that has several subclasses: World, Vault, etc.
I fill a vector with these classes and then cannot go through and
delete them. What's the trick to deleting pointers from a vector?
Code:
std::vector<Scene*> scenes;
void initializeGame()
{
robot = new Robot("COM2");
player = new Player();
//Add Scenes
scenes.push_back(new World(robot, player));
scenes.push_back(new SecurityWires(robot));
scenes.push_back(new Keypad(robot));
scenes.push_back(new Maze(robot, player));
scenes.push_back(new Explosives(robot, player));
scenes.push_back(new Vault(robot));
scenes.push_back(new Map());
}
void endGame()
{
for(int i = 0; i < scenes.size(); i++)
{
delete scenes;
}
scenes.clear();
}
When my program starts, I call intializeGame. When I go to exit the
game, I call endGame() and I get an assertion failure. Any ideas?
I fill a vector with these classes and then cannot go through and
delete them. What's the trick to deleting pointers from a vector?
Code:
std::vector<Scene*> scenes;
void initializeGame()
{
robot = new Robot("COM2");
player = new Player();
//Add Scenes
scenes.push_back(new World(robot, player));
scenes.push_back(new SecurityWires(robot));
scenes.push_back(new Keypad(robot));
scenes.push_back(new Maze(robot, player));
scenes.push_back(new Explosives(robot, player));
scenes.push_back(new Vault(robot));
scenes.push_back(new Map());
}
void endGame()
{
for(int i = 0; i < scenes.size(); i++)
{
delete scenes;
}
scenes.clear();
}
When my program starts, I call intializeGame. When I go to exit the
game, I call endGame() and I get an assertion failure. Any ideas?