-1

I have a vector set up as follows:

vector< vector<myClass>* > vec;

I am having trouble deleting elements from vec however, I have dynamically allocated all elements in vec, and am trying to delete the ith element as follows:

vector<myClass> *victim = vec[i];
delete victim;
victim = 0;

However this does not seem to be correctly removing them from vec. What am I missing here?

Kaze
  • 1

1 Answers1

1

try using vector::erase to remove it from the vector. The delete will free the memory only but the vector will keep the pointer unless you removed it.

have a look at this answer https://stackoverflow.com/a/3385251/249120

Community
  • 1
  • 1
ahmedsafan86
  • 1,776
  • 1
  • 26
  • 49