# Strange #include problem

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

## Recommended Posts

The problem in question is one related to turning a part of my program into an object. I finally got glFont to work with some sloppy quick procedural code, so as usual I'm now making everything neat and nice and putting it in a class. However, a strange problem has arisen. This error: expected init-declarator before ';' token and expected ',' or ';' before '*' token Here's the file that the error is showing up in:
#ifndef GLOBALS__H
#define GLOBALS__H

#include <allegro.h>
#include <alleggl.h>

#include "camera.h"
#include "debug.h"
#include "draw.h"
#include "gamemanager.h"
#include "gfx.h"
#include "logic.h"
#include "mouse.h"
#include "screen.h"
#include "text.h"

#include "glfont2.h"
using namespace glfont;

extern volatile unsigned int timer;

extern                  objCamera*       Camera;
extern                  objDebug*        Debug;
extern                  objDraw*         Draw;
extern                  objGameManager*  GameManager;
extern                  objGfx*          Gfx;
extern                  objLogic*        Logic;
extern                  objMouse*        Mouse;
extern                  objScreen*       Screen;
extern                  objText*         Text;

extern const char*      MOUSE_SPRITE;
extern const char*      TITLE_BACKGROUND;

extern GLuint           texTitleBackground;

extern GLFont           testFont;
extern GLuint           texTestFont;

#endif

and here is the header that broke it
#ifndef TEXT__H
#define TEXT__H

#include <allegro.h>
#include <alleggl.h>
#include <string>
#include <utility>

#include "defines.h"
#include "globals.h"

#include "glfont2.h"
using namespace glfont;

class objText
{
private:
public:
objText();
~objText();
void Out(char*, GLFont, float, float, float, int);
};

#endif

Prior to the line #include "text.h" being added into the first file, everything compiled flawlessly. Trying to add the objText header broke it... Somehow. Keep in mind that this worked when I did it procedurally. The extern objText* Text; business was there when it worked. It was the specific act of adding that #include

##### Share on other sites
Which line does the error point you to?
[edit: I suspect it is in glfont2.h. Note that using namespace in headers is bad karma. ]
[edit2: Note also that you have circular inclusion. text.h includes globals.h and globals.h include text.h. Choose one or the other, but not both. ]

##### Share on other sites
Quote:
 Original post by jflangloisWhich line does the error point you to?

extern objText* Text;

The thing is, this was there before and it worked. When I usually get this error, it means I didn't included the objects header, and it's solved by including the header. So this is an error I should get if i DIDN'T include text.h... But changing to this format and #including text.h all of a sudden makes it not work.

The error tells me it doesn't know what objText is, but I included the header sooooo... I dunno

##### Share on other sites
Remove #include "globals.h" from text.h.

##### Share on other sites
Quote:
 Original post by jflangloisRemove #include "globals.h" from text.h.

Interesting, it worked... But why?

##### Share on other sites
Which compiler is this? As I said in my second edit, you had a circular include. I suppose that it's possible that the compiler, instead of complaining about it, stopped including after a set amount of times and had the contents of globals.h first, at which point objText was not declared.

Hint: if your compiler allows you to just do the preprocessor pass, choose that and look at the output.

[Edited by - jflanglois on July 6, 2006 10:30:46 PM]

##### Share on other sites
Quote:
 Original post by jflangloisWhich compiler is this? As I said in my second edit, you had a circular include. I suppose that it's possible that the compiler, instead of complaining about it, stopped including after a set amount of times and had the contents of globals.h first, at which point objText was not defined.

g++

And I realized previously that the includes were circular, but I didn't think that was a problem because I've been doing that the entire program, lol. I've pretty much just put globals and defines.h in every file, and I hadn't had any problems until this object.

##### Share on other sites
Interesting, I would have expected VC8 to complain about circular inclusion, but it does the same as GCC 3.2.3.

Anyway, I stand by my explanation:

global.h:
#ifndef GLOBAL_H#define GLOBAL_H#include "test.h"extern Test *test;#endif

test.h:
#ifndef TEST_H#define TEST_H#include "global.h"struct Test {	void Do();};#endif

test.cpp:
#include "test.h" // If you change this to globals.h, it compiles fine, since it includes test.h "before" global.h ("after" recursively)void Test::Do() {}int main() {}

[edit: Result of cpp test.cc (C Preprocessor):
# 1 "test.cc"# 1 "<built-in>"# 1 "<command line>"# 1 "test.cc"# 1 "test.h" 1# 1 "glob.h" 1# 1 "test.h" 1# 5 "glob.h" 2Test is not yet declaredextern Test * test;# 5 "test.h" 2Test is defined here, after the pointerstruct Test {  void Do();};# 2 "test.cc" 2void Test::Do() {}int main() {}
]

The moral of the story: only include what is necessary for a particular translation unit.

jfl.

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 12
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632168
• Total Posts
3004529

×