Class Datatype Not Working Even With #included File

Started by
3 comments, last by Kylotan 17 years, 1 month ago
I have a derived class from an abstract base class that creates an object of another class privately inside of it. I have included the header files with the class definitions in it, but the private class object's class datatype isn't working when I compile. Here's what it looks like: scenes.h:
#ifndef _SCENES_H_
#define _SCENES_H_

#include "common.h"
#include "scene.h"
#include "CMap.h"


//Game
class CGame: public CScene
{
private:
	CMap *Map;    //<---------------Problem here (look below at error)

public:
	CGame();
	~CGame();

	void render(){}
	UInt8 loop(){return 0;}
};

#endif
CMap.h:
#ifndef _CMAP_H_
#define _CMAP_H_

#include "common.h"

class CMap
{
private:
	sMapHeader Header;
	sMapParam Param;
	vector<SDL_Surface> vTextures;
	vector<string> vstrTextures;
	sMapBase *pMap;
	SInt16 *pMapDecor;

	SDL_Surface *MapSurface;

	bool loadMap(string filename);
	void loadTextures();

public:
	CMap(string filename){ if(!loadMap(filename)){ loadTextures(); } }
};

#endif
And I get this error when I compile:
c:\Users\xxxx\Documents\Visual Studio Projects\Neon\scenes.h(24) : error C2143: syntax error : missing ';' before '*'
c:\Users\xxxx\Documents\Visual Studio Projects\Neon\scenes.h(24) : error C2501: 'CGame::CMap' : missing storage-class or type specifiers
c:\Users\xxxx\Documents\Visual Studio Projects\Neon\scenes.h(24) : error C2501: 'CGame::Map' : missing storage-class or type specifiers
I can't figure out for the life of me why it can't simply see the CMap class. I've even started a new project over from scratch, added the source files again, and compiled, but I get the same errors. Thanks in advance! Edit: I'm using MSVC++ 2003 .NET
-Conrad
Advertisement
I just put:

class CMap;

in my scenes.h file. It works now, but I'm still curious as to why it wouldn't find the CMap class even when directly linked to the #include.
-Conrad
Do you, by any chance, have a cycle in your #includes?
I just might. I'm never sure how to setup includes properly. Do includes work in a hierarchy. Say I have a class defined in a header which I include in another common header file inside another header which I finally include in the header I need. So that's nested 4 times of includes that all trace back to the one file. Is that a good way to go about it?
-Conrad
#Includes don't have hierarchies as such. They're just text substitution, in the order you type them in the files. You have to ensure that any given file you compile brings in the headers in the correct order, bearing in mind that if those headers refer to each other, even indirectly, that order will get affected by the inclusion guards.

This topic is closed to new replies.

Advertisement