Sign in to follow this  

Class Datatype Not Working Even With #included File

This topic is 3931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
#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.

Share this post


Link to post
Share on other sites

This topic is 3931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this