delete of memory

Hello everyone, I have a question.

HumanPlayer is a class and players is a vector<HumanPlayers*>.

1
2
3
4
5
6
7
for(int i = 1 ; i <= num ; ++i){
	players.push_back(new HumanPlayer());
}

for(int i = 0 ; i < num ; ++i){
       	delete players[i];
}


With this code am I able to delete all the vector's elements previously allocated?
With this code am I able to delete all the vector's elements previously allocated?

Yes.

edit:
Clarification: You're deleting each of the players allocated at line 2. You're not deleting the elements of the vector itself. For that you need:
 
  players.clear();  // After line 7 


Last edited on
Topic archived. No new replies allowed.