My problem is the array Field which is considered by the compiler as undeclared. I declared the array in main and i'm trying to access it through the following .cpp file.
animals.cpp :
#include <cstdlib>
#include "organisms.h"
#include "animals.h" // class's header file
// class constructor
Animals::Animals()
{
}
void Animals::checkMovement()
{
int gi, gj;
organisms* temp; //<--------The problem is here
do{
gi = (posi-1)+rand()%(posi+1);
gj = (posj-1)+rand()%(posj+1);
if(Field[gi][gj] == NULL) //And here
{
temp = Field[posi][posj];
Field[posi][posj] = Field[gi][gj];
Field[gi][gj] = temp;
break;
}
}while(Field[gi][gj] != NULL);
posi = gi;
posj = gj;
N++;
}
organisms is the base class and animals is the derived class. How can I fix this? Thank you in advance.