I am not new to programming, but I am new to c++, I have a strong Java background. So I am struggling a little bit with some of the more specific syntax (ie required whitespaces at end of file, using * and &)
If it isn't obvious this is a simple Maze game, there is a maze, and aguy who wants to get from point a to point b (the maze runner)
When I go to compile, this is the error I get:
Code:
<command line>:1:17: warning: ISO C requires whitespace after the macro name
In file included from c:/Users/Danny/dev/NetBeansProjects/MazeGame/Maze.h:13,
from c:/Users/Danny/dev/NetBeansProjects/MazeGame/Maze.cpp:8:
c:/Users/Danny/dev/NetBeansProjects/MazeGame/MazeRunner.h:27: error: ISO C++ forbids declaration of `Maze' with no type
c:/Users/Danny/dev/NetBeansProjects/MazeGame/MazeRunner.h:27: error: expected `;' before '*' token
Here is Maze.h
Code:
#ifndef _MAZE_H
#define _MAZE_H
#include "Tile.h"
#include "MazeRunner.h"
#include <vector>
namespace mazegame
{
class Maze
{
private:
unsigned int maze_rows;
unsigned int maze_cols;
std::vector<std::vector<char> > maze_char;
unsigned int starting_location;
public:
Maze(unsigned int _maze_rows, unsigned int _maze_cols);
Maze(const Maze& orig);
virtual ~Maze();
void generateMaze();
void clearMaze();
void printMaze();
std::vector<mazegame::Tile*> getTiles();
MazeRunner* getMazeRunner(unsigned short _player_num);
};
};
#endif /* _MAZE_H */
and here is MazeRunner.h
Code:
#include "Maze.h"
#ifndef _MAZERUNNER_H
#define _MAZERUNNER_H
namespace mazegame
{
class MazeRunner
{
public:
enum Input
{
MOVE_UP,
MOVE_DOWN,
MOVE_LEFT,
MOVE_RIGHT
};
private:
Maze* maze;
unsigned int xloc;
unsigned int yloc;
public:
MazeRunner(unsigned int _xloc, unsigned int _yloc);
MazeRunner(const MazeRunner& orig);
virtual ~MazeRunner();
void processInput(Input input);
unsigned int getX();
unsigned int getY();
};
};
#endif /* _MAZERUNNER_H */
I could compile and run my program just fine until I added the below code into MazeRunner.h
Code:
#include "Maze.h"
.
.
.
.
private:
Maze* maze;
which causes the compile error above. I believe I am following everything correctly, and this is pretty much driving me mad.
Any assistance in helping me find the answer to my problem would be greatly appreciated.
edit: after looking again, I think the issue might be that I need to include MazeRunner.h in Maze.h and I need to include Maze.h in MazeRunner.h, so one of them (in this case MazeRunner) is being declared before Maze gets the chance because of the order in how the files are included. Though I am not sure how to rectify this.... I think I may have hit a chicken and egg type problem.