I am trying to understand how to delete a vector of pointers, and the pointed objects, in memory. I have started with a simple example, found in another thread, but I get "pointer being freed was not allocated" error.
What I am doing wrong?
#include <vector>
#include <algorithm>
#include <iostream>
int main(){
std::vector <int *> vec;
int a = 2;
int * b = &a;
int c = 3;
int * d = &c;
vec.push_back(b);
vec.push_back(d);
for (int i = 0; i < vec.size(); i++) {
delete vec[i];
}
vec.clear();
}