I've got two classes, and each one has a pointer to another. However, I'm having trouble with one of them. Actor.h is acting like the other class doesn't exist.
[code="C++"]//---------------------------------------------------------------------------
// A map tile
//---------------------------------------------------------------------------
#ifndef TILE_H
#define TILE_H
#include <string>
#include "Actor.h"
using namespace std;
class Tile
{
public:
//-----------------------------------------------------------------------
// Default Constructor
Tile();
//-----------------------------------------------------------------------
// Copy Constructor
Tile(const Tile&);
//-----------------------------------------------------------------------
// Destructor
~Tile();
//-----------------------------------------------------------------------
// Assignment Operator
const Tile& operator=(const Tile&);
//-----------------------------------------------------------------------
// Getters/Setters
string getName() const;
void setName(const string);
int getX() const;
void setX(const int);
int getY() const;
void setY(const int);
int getImgX() const;
void setImgX(const int);
int getImgY() const;
void setImgY(const int);
Actor* getOccupant() const;
void setOccupant(Act or*);
private:
//The name, or index of the tile
string name;
//The coordinates of the tile on the map
int x;
int y;
//The coordinates of the tile image within the graphics file
int imgX;
int imgY;
Actor* occupant;
//ArrayList Items
};
#endif[/code]
[code="c++"]//---------------------------------------------------------------------------
// The basic building block for players and monsters
//---------------------------------------------------------------------------
#ifndef ACTOR_H
#define ACTOR_H
#include <string>
#include "Tile.h"
using namespace std;
class Actor
{
public:
Actor();
Actor(Actor&);
~Actor();
protected:
Tile* position;
int health;
int maxHealth;
int strength;
int dexterity;
string name;
int imgX;
int imgY;
string imageName;
};
#endif[/code]
For some reason, I get the error:
1>c:\c++\tilequ est\tilequest\a ctor.h(19) : error C2143: syntax error : missing ';' before '*'
1>c:\c++\tilequ est\tilequest\a ctor.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\c++\tilequ est\tilequest\a ctor.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
However, there is no error if I change "Tile* position" to "int* position". It almost seems as if it doesn't recognize Tile as a class. Could this be because they're both #including each other? What am I doing wrong?
[code="C++"]//---------------------------------------------------------------------------
// A map tile
//---------------------------------------------------------------------------
#ifndef TILE_H
#define TILE_H
#include <string>
#include "Actor.h"
using namespace std;
class Tile
{
public:
//-----------------------------------------------------------------------
// Default Constructor
Tile();
//-----------------------------------------------------------------------
// Copy Constructor
Tile(const Tile&);
//-----------------------------------------------------------------------
// Destructor
~Tile();
//-----------------------------------------------------------------------
// Assignment Operator
const Tile& operator=(const Tile&);
//-----------------------------------------------------------------------
// Getters/Setters
string getName() const;
void setName(const string);
int getX() const;
void setX(const int);
int getY() const;
void setY(const int);
int getImgX() const;
void setImgX(const int);
int getImgY() const;
void setImgY(const int);
Actor* getOccupant() const;
void setOccupant(Act or*);
private:
//The name, or index of the tile
string name;
//The coordinates of the tile on the map
int x;
int y;
//The coordinates of the tile image within the graphics file
int imgX;
int imgY;
Actor* occupant;
//ArrayList Items
};
#endif[/code]
[code="c++"]//---------------------------------------------------------------------------
// The basic building block for players and monsters
//---------------------------------------------------------------------------
#ifndef ACTOR_H
#define ACTOR_H
#include <string>
#include "Tile.h"
using namespace std;
class Actor
{
public:
Actor();
Actor(Actor&);
~Actor();
protected:
Tile* position;
int health;
int maxHealth;
int strength;
int dexterity;
string name;
int imgX;
int imgY;
string imageName;
};
#endif[/code]
For some reason, I get the error:
1>c:\c++\tilequ est\tilequest\a ctor.h(19) : error C2143: syntax error : missing ';' before '*'
1>c:\c++\tilequ est\tilequest\a ctor.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\c++\tilequ est\tilequest\a ctor.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
However, there is no error if I change "Tile* position" to "int* position". It almost seems as if it doesn't recognize Tile as a class. Could this be because they're both #including each other? What am I doing wrong?
Comment