Public Group

# Class Datatype Not Working Even With #included File

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

## 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:
sMapParam Param;
vector<SDL_Surface> vTextures;
vector<string> vstrTextures;
sMapBase *pMap;
SInt16 *pMapDecor;

SDL_Surface *MapSurface;

public:
};

#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 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 on other sites
Do you, by any chance, have a cycle in your #includes?

##### 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 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.

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999492
×