Im having a little problem with classes.
Here is some of my code:
//GameMap.h
#ifndef GAMEMAP_H
#define GAMEMAP_H
#include "apath.h"
class GameMap
{
/*class definition here*/
};
#endif
and
//apath.h
#ifndef APATH_H
#define APATH_H
class path
{
//some code...
void DoSomething(GameMap map);
//rest of class body
};
#endif
I cant use GameMap in apath.h, when I try to include “GameMap.h in this file I get some stupid errors… I also tried to add class GameMap; before definition of path class. Nothing helped… I really need to use it here…
If needed I can post some more code.
Thanx for any replies!
You should use forward declaration of class
GameMapin apath.h:Check: When can I use a forward declaration?
In following example I use forward declaration of class
Aso that I’m able to declare functionuseAthat uses it:and then in main.cpp I have:
which is absolutely correct, since class A is already defined here.
Hope this helps.