In the last few days I tried to understand some basic concepts in making games, and I'm stuck at the object oriented part. I made a few games in a program named game maker in the last years, and I was trying to implement a similar mechanism in c++.
I don't know much c++, maybe the basics. I created a simple ~simulation, where little cells reproduce and die. My problem is, that I create objects, but can't properly delete them. And that results in eating up the memory. If anyone could help me understand what am I doing wrong, I would be grateful. Here's the code:
The creation code:
blbob *tmp;
tmp = new blbob;
tmp->x = x;
tmp->y = y;
blbob_numb++;
in the while loop:
it=obj_list.begin();
while(it!=obj_list.end()) {
if((*it)->z==1) {
(*it)->step();
it++;
}else {
it = obj_list.erase(it);
}
}
And if I try to delete it using "delete", i get an error in vc++ and nothing in codeblocks.
in the destructor:
~blbob() {
it = obj_list.erase(it);
}
in the while loop
while(it!=obj_list.end()) {
if((*it)->z==1) {
(*it)->step();
it++;
}else {
delete *it;
}
}