I cannot use Vectors specifically for this school assignment. Most of the answers I found simply state that "you must use vectors" as the most voted comment. Although I appreciate and understand this, I simply cannot use them for this assignment.
This is the purpose of C ++ with dynamic memory management as follows:
int numAnimals;
int capacity;
Animal** animals;
void addAnimal(Animal *newAnimal);
capacity = 10;
numAnimals = 0;
animals = new Animal*[capacity];
void SampleClass::addAnimal(Animal *newAnimal)
{
for (int i = 0; i < capacity; i++){
if(animals[i]){
i++;
}else{
animals[i] = newAnimal;
numAnimals++;
break;
}
}
}
animals is a pointer to a pointer, in this case a pointer to an array of pointers to the type of the Animal object that has not yet been created.
"addAnimal" , , , , , . , .
- - , " " .
, :
if (animals [i]), , , , , , , "else", - , , , , -, , .
, , ? , , , .
, , , , ++ stackoverflow . , , [], .
, !