Someone must have an answer for me...
Also, new problem. Yesterday, it was working fine, but today, I loaded the program and no new bunnies were being born, even though I was getting an even amount of males and females. I have no idea what's wrong and why it's doing this.
EDIT: Fixed the problem where bunnies weren't being born. For some reason, my header files weren't set to link with the project. Now, my problem is that segmentation fault. It only happens in the phase where bunnies die. So the problem must lie somewhere in this section:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// Bunnies will now age.
for(int i = 0;i < bunnies->length();i++) {
bunnies->get(i)->mature();
if(!(bunnies->get(i)->isVampire())) {
if(bunnies->get(i)->getAge() > 10) {
cout << "Bunny " << bunnies->get(i)->getName() << " has died!" << endl;
bunnies->remove(i);
}
} else {
if(bunnies->get(i)->getAge() > 50) {
cout << "Vampire Bunny " << bunnies->get(i)->getName() << " has died!" << endl;
bunnies->remove(i);
}
}
}
|
But I don't see what could be causing the problem. I've checked the constructors and I'm not forgetting to assign anything... and even if I had, the segmentation fault would have come when the Bunny object was first created. So why is a segmentation fault happening when I try to kill off the Bunny objects? And why is it only happening sometimes? Sometimes, it works just fine, and will go through several cycles killing off bunnies without any problems, but then it will seg fault on a random cycle.
Does anyone have any insight into my problem?