int buffer[gSizeOfGrid][gSizeOfGrid];
CList *currentCList;
Grid *currentGrid; //this line get the error
int aroundinfo[4];
//other functions are not revelant maybe? They don't
//use currentGrid.
the class Grid has the header:
class Grid
{
public:
Grid();
//create default cList object for the grid .
Grid(CList*);
//create cList and bind existing clist object.
bool rebind(CList*);
//rebind cList.
~Grid();
void init(int ants,int bugs);
//init a grid with ants and bugs according to parameter.
void GetSnapshot();
//synchronize grid buffer with clist.
void Step();
//make the world go on!
bool spawn(Creature&,Position);
//create a creature on the grid.
//if success, return true.
//if there are already another creature return false.
void move(Position,int);
void eat(Position,int);
void breed(Position,int);
void destroy(Position);
private:
CList* theList;
};
the Clist Class looks the same but is Okay in declaration:
using namespace std;
class CList
{
public:
CList();
int CreateObject(Creature&,Position);
Creature& GetObject(int);
bool RemoveObject(Position);
bool RemoveObject(int);
int getType(Position);
void cleanup();
vector<Creature*> list;
int size();
};
Why the Grid* declaration goes wrong but CList* is OK? Thank you!
This is because
class Gridis not visible to the pointercurrentGrid. Just do following and it should work;I assume that you may not want to
#includetheGridheader before this declaration as,Griditself is usingCList. The best way should be to include all the headers before this declarations.