For a C++-project, I need to make a game with Doodlebugs and Ants, which are both Organisms. So, I made a class called Organism
with the following definition (although I'll probably add way more member functions and member variables, of course).
Organism.h:
#ifndef ORGANISM_H
#define ORGANISM_H
#include "World.h"
class Organism
{
public:
Organism();
~Organism();
virtual void Move() = 0;
friend class World;
int survivalTime;
};
#endif
Organisms live in 'the World', which is a class with (among others) a member variable Organism*** field
, a two-dimensional dynamic array containing pointers to Organism objects.
World.h:
#ifndef WORLD_H
#define WORLD_H
#include "Organism.h"
#include "Ant.h"
#include "Doodlebug.h"
class World
{
public:
World();
~World();
void gameplay();
Organism*** field;
};
#endif
You probably already guessed it: Ant
and Doodlebug
are derived from Organism
.
Ant.h:
#ifndef ANT_H
#define ANT_H
#include "Organism.h"
class Ant : public Organism
{
public:
Ant();
~Ant();
void Move();
};
#endif
Doodlebug.h:
#ifndef DOODLEBUG_H
#define DOODLEBUG_H
#include "Organism.h"
class Doodlebug : public Organism
{
public:
Doodlebug();
~Doodlebug();
void Move();
};
#endif
As you can see, Ant.h
and Doodlebug.h
are almost identical, except for the words Doodlebug and Ant. However, I have two errors.
- In
World.h
, line 16: "'Organism' does not name a type." - In
Doodlebug.h
, line 7: "expected class-name before '{' token"
Why is this? The first error can be solved by putting class Organism;
right before the definition of class World
, but I don't understand why that changes anything, since the complete definition of Organism
is in Organism.h
, which I include.
The second error is the one I'm VERY confused by (and kind of the main reason I'm asking this question), since Ant.h
is identical to Doodlebug.h
except for the words Ant
and Doodlebug
, but in Doodlebug.h
I get an error but not in Ant.h
???
Any help is greatly appreciated.